process and process management :
Clear screen: System ("clear"); #include <signal.h>
System calls:
Write (file descriptor, string, string size). Read (file descriptor, string, string size), reads the contents of the previous ' string size ' in the file and saves it to the string (and as long as open does not change the opening mode, the default is to block the process when the file contents are empty), and success returns the read string size (0-' string size '), otherwise returns-1.
Open (file name, open mode), returns the file descriptor. Close (file descriptor), closes the file opened with open, so the parameter file descriptor is returned for open.
process environment and process properties :
What is a process: Simply put, a process is the process of executing a program.
Process state: Process Tri-State: Run state, ready state, blocking state-the state can change under certain conditions. (where the waiting process is divided into: interruptible processes can be signaled to wait, and non-disruptive processes cannot be interrupted under any circumstances, waiting for the condition to be met). Zombie Process: The child process exits before the parent process, and the child process is referred to as the zombie process zombie (because only the parent process can be reclaimed, and the parent process does not reclaim its resources) before the child process terminates to the parent process call Wait (): The parent process exits before the child process. Child process is called orphan process (is process 0/init process?). Recycling
Execution mode and type of the process: execution mode is divided into user mode-interrupt/system call, kernel mode. Process types are divided into user processes-interrupts/system calls, system processes.
Properties of the process: View the properties of the process: non-real-time PS aux/auxf, real-time top. The meaning of each column (see it in a free time). Session (a collection of process groups): A session can have no control terminal, can also establish a connection with a terminal, establish a connected session first process called the control process; A session can have several process groups, which can be divided into a foreground process group (when the session comes with a terminal) and multiple background process groups. Its characteristics: whenever the terminal input interrupt signal (CTRL + C) or the terminal's exit key, there will be an interrupt signal or exit signal sent to the foreground process group of all processes.
Get/Set Process group number (Pgid): Getpgid (PID)/int setpgid (PID, Pgid), get session number of the process: GetSID (SID); Create session: pid_t Setsid () returns the process number, which acts as the session first process. Control terminal functions: pid_t tcgetpgrp (int filedes), pid_t tcsetpgrp (int filedes, pid_t pgrpid), pid_t tcgetsid (int filedes) (see for free).
Process User properties:
Real user number (RUID), valid user number (EUID), process user number (GID), active process user group number (EGID): See for free.
management of the process :
Create a process: pid_t fork (); After execution succeeds, if the parent process grabs the execution, it returns the PID of the child process, returns 0 if the child process grabs execution, or fails, returns 1; This function is a system call that replicates the parent process, so the child process is almost identical to the parent process. , the file is shared, but the data and file descriptors are exclusive . The/vfork () function shares the data space with the parent process, which is more efficient and executes in order after the child's father .
Exit Process:
On_exit (Test_exit, (void *) str), the function has two parameters, the first is: Call the Test_exit function before the end of the process, such as void test_exit (int status, void *arg) {...},test_ The first argument of the Exit function must be the status of exit at the end of the process, and the second parameter, which should be more than the argument in the example, is the STR that is passed to the Test_exit function, Arg.
Normal end of process void exit (int status): The process's buffer data is automatically written back, closing files that are not closed. #include <stdlib.h>
void _exit (int status): The process's buffer data is not automatically written back, and the file is not automatically closed. #include <unistd.h>
Waits for a process (waits for a child process to break or end): pid_t wait (int *status); stops execution of the current process until a signal arrives or its child processes end. If the child process is finished, the child process ID and end state (saved in the parameter status) are returned immediately when the wait is executed. Status can also be not written, there are some test macros (#include <stdlib.h>). There is an error (No child process) returns-1. When a child process is found to terminate, it releases the task_struct and system space stack (that is, the resource) occupied by the child process according to its PID, and then adds the CPU usage time of the child process to its parent process.
Replace current process: #include <unistd.h>
int execl (const char *path, const char *arg, ...), int execlp (const *file, const char *arg, ...), int execv (const char *path , const char *argv[]), int execvp (const char *file, const char *argv[]), Execve (const char *filename, const char *argv[], CO NST Char *envp[])
The scheduling algorithm for the process (temporarily regardless).
inter-process communication :
Some basic concepts:
Process synchronization: A feature is not completed and will not be returned (one thing done before you do the next piece)
Process Async: Each do each, whenever one thing is done, notify the caller.
IPC: interprocess communication. Each IPC mechanism has a unique ID that is created by key.
Three IPC mechanisms that inherit from System V: semaphores, message queues, shared memory.
Same as host, inter-process asynchronous mechanism: signal (signal)
Signal Installation:
Signal (signal, function)--the function can take no parameters, or a parameter (parameter is a signal, the signal is a bunch of int values).
Sigaction (signal, signal structure, signal structure). --The second parameter installs the current signal (if it is a null pointer, the original signal remains the same), and the third is the previous signal structure.
Signal structure: 1,. sa_handler Signal processing function. 2,. Sa_mask signal processing function during the execution of the other signals blocked out. 3.. sa_flags is used to change the behavior of the specified signal.
Same host, inter-process synchronization mechanism: Semaphore (semaphore)
With the host, inter-process data interaction mechanism: nameless pipe (pipe), known pipeline (FIFO), Message Queuing, memory mapping, shared memory , pipeline and Message Queuing all have synchronization mechanism, memory mapping, shared memory is not synchronized.
The pipeline is not created without a header file.
Nameless Pipe PIPE: Each pipe has only one memory page to do the ring buffer, with two pipes can achieve full duplex.
Pipeline creation: int pipe (int files[2]); The parameter is a file descriptor, 0 is read, 1 is write, 0 is returned successfully, otherwise-1; the written data disappears when it is read. Data interactions between processes can then be performed through two file descriptors files[0], files[1].
Named pipes can be saved as special device files in the file system, so processes can do I/O through named pipes at any time.
Named pipe creation: by command: Mkfifo FileName (can also be used by command, delete FIFO), system call: int Mkfifo (file name, pipe file permission), Success returns file descriptor, otherwise returns-1.
Network, inter-host data interaction mechanism: socket (socket)
Linux Process Learning