8th Chapter Process Control Summary

Source: Internet
Author: User

1 program space for parent-child processes

The child process obtains a copy of the parent process's data space, heap, stack, that is, the space is not shared

Parent-Child process shared body segment

But now many implementations use cow write-time replication technology, which is a shared space, making a copy only for modified regions when a modification occurs

2 File Sharing

Parent-child processes maintain process table entries (records have file descriptors, file descriptor flags, File table pointers)

Parent-Child Process shared file table (record current file offset, file status flag, v-node pointer)

A file with only one v node table

3 vfork

Vfork the child process created is intended to call the EXEC function

Before calling the EXEC function, the parent-child process shares the program space (because after calling exec, the child process accesses the additional program space and does not need to copy the program space of the parent process separately for the child process before calling exec)

Vfork guarantees that the child process runs first until the child process calls the Exec or Exit function stepfather the process starts running

4 wait

pid_t Wait (int *status) pid_t waitpid (pid_t pid,int *status,int option)

The wait function waits for a process in all child processes to terminate, writes the terminating state to status, and returns the child process ID

The Waitpid function waits for a child process by PID, option to decide whether to block

For the child process termination state that wait gets, it can be judged by the following macro:

wifexited (status) wifsignaled (status) wifstopped (status) wifcontinued (status)

The Waitpid function adds a parameter to the WAIT4 function to get the resource usage of the child process:

pid_t wait4 (pid_t pid,int *status,int option,strcut rusage *rusage)

wait3 function does not specify child process PID

5 exec function

int execl (constchar *pathname,constchar *arg0,... /*  */)int execv (constchar *pathname,Char *  Const argv[])

The pathname parameter of the EXECL and EXECV functions specifies the path of the executing program (absolute path, relative path, or file name directly under the current directory)

Exelce and Execve add char *const env[] parameter pass environment variable

The first parameter of EXECLP and EXECVP if it is not a pathname, the executable file is found in path (if the file name is only found under path and will not be found in the current directory)

8th Chapter Process Control Summary

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.