[Linux Study Notes] process concepts and Control

Source: Internet
Author: User

Content: process identification, running, termination, inter-process competition, and process operations

1. process running and Termination

Each process has a unique ID. The system process Swapper with ID 0 is called a switching process and is a system scheduling process. The process with ID 1 init is a user process, reads system-related initialization files. The process with ID 2 is a pagedaemon page sprite process and a system process. These processes are special and cannot be aborted.

Some functions related to process running and termination: fork, vfork, exec, and exit.

The fork function is the only way to create a new process in Linux. The fork function can be used to create user processes except the exchange process, INIT process, and page genie process.

The vfork function is used to create a new process. After the process is established, execute exec to execute a new process.Program.

Exec itself cannot create a new process, because the ID of the original parent process and child process does not change before and after exec is executed.

The exit function calls the clearing function registered by atexit and closes all standard I/O streams. The exit status of a process is very important. Generally, a value of 0 indicates normal exit.

The function is prototype:

# Include <sys/types. h> # include <unistd. h> pid_t fork (void); pid_t vfork (void); // # include <unistd. h> int execl (const char * pathname, const char arg0 ,...); int execv (const char * pathname, char * const argv []); int execle (const char * pathname, const char * arg0 ,...); int execve (const char * pathname, char * const argv [], char * const envp []); int excelp (const * filename, const char * arg0 ,...); int execvp (const char * filename, char * const argv []); // # inlcude <stdlib. h> void exit (INT status); # inlcude <unistd. h> void _ exit (INT status );

2. Wait operations

When wait or waitpid is called, the process may be in the following three States: blocking (when all its sub-processes are still running) and terminating (return immediately) and return immediately (no sub-process) if an error occurs ).

Wait Function Format:

 
# Include <sys/types. h> # include <sys/Wait. H> pid_t wait (int * statloc); pid_t waitpid (pid_t PID, int statloc, int options );

// If the process is successful, the process ID is returned. If the process fails, the return value is-1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.