1. process: ps, getpid (), fork (),>
getpid library function-number acquiring process is
a multi-process
under the first row is the parent process, the process of the second line sub-
process applications, the concept of concurrent following
applications concurrently, the server in the
following server
following code for the above analysis
2. signal: signal (, EXIT.)
How to get the program running in the background
signal for the process
as essentially a macro signal names
ending above named child process sends a signal to the parent SIGCHLD
, if the parent process does not handle the signal, and that the child process becomes a zombie process.
The signal value of 11 is their illegal use or indiscriminate use of null pointer addresses, and even add the same signal values 9 ignore the code can not be ignored.
A third recovery signal processing method as default values generally do not, as a custom function EXIT function
following the function is custom EXIT function, because the global variable is set TcpServer EXIT function to access it and to close the socket
as ctrl + c and kill / kill all eXIT command can call the function to shut down the process, but not to kill the process, and called the notice of withdrawal
following is the operating system kill command signal, not kill C language functions. kill other users can not kill the process
kill function returns a value of 0 on success, -1 Failure. This feature will be used in the monitoring process, the following argv [1] is the first parameter i.e. kill pid number, argv [2] The second parameter is a signal value
3. The inter-process communication: shmget ()
Process data space is independent of each other, they can not communicate. However, in some cases required inter-process communication with each other to complete the system, or a function to exchange data
following communication scenario is the process
message queue similar socket, but only in the machine. General shared memory and semaphores combined with
5 sample program: a pointer operation is equivalent to the shared memory operation
is written is the string "process of this program ...", redis do not have to write their own shared memory
4. Multithreading: pthread_create ()
The first parameter in pthread_t (data type): typedef unsigned long int pthread_t, unsigned long
new customers start a thread on the end of the process rather than the company, following the thread to see how to write the main function, pthread_create is a C language library functions
will thread_start changed pth_main (thread main function)
as it is written in the form above, so
below in the server
print below the socket
as (void*)ii = void*arg
a single multi-threaded process: kill only process (kill thread does not exist), the process of killing threads automatically exit
multiple processes: parent was killed, not to reclaim the child process
multiple threads will not complete the assignment thread switching, the value is removed, not the original value of that value
5. Thread Synchronization: pthread_mutex_t
pthread_mutex_t structure. Data input: landing page. Data show: java, Microsoft .net, c #. Shared resources: 全局变量
, 全局对象
(database conjunctions, socket, log file objects)
to open the way to a +, because the log files continue to the end of the additional content
as book242 not the contents written on the screen but the log file is written
after the top kill process killall book242 View .log files can be displayed, the following modifications are optional buffer write buffer to solve the problem of
multiple threads share resources with logfile, may be a problem (file content writing disorder), logfile to define a lock, a lock a shared resource
above before writing operation and the same log, the surface can not see the effect, the following modifications sleep one second
to 20 client 30 sent message is not flashed, and lock with 1 second, so to be finished (20 * 30 )second