Apue Study Notes-Process Control

Source: Internet
Author: User
1. getpid can get the process ID. Getppid can be used to obtain the ID of the Process calling process.
2. Fork function: one call and two returns: 0 is returned in the subprocess. Returns other values in the parent process. If it is greater than 0, it is the sub-process ID; otherwise, it fails.
3. The child process obtains the data space (data, BSS), heap, and stack copies of the parent process. The body segments are shared between processes.
4. The current implementation generally does not perform full replication, but implements write-time replication: and often read-only shared parts. If a process modifies a piece of memory, it creates a copy for this piece of memory.
5. The child process generated by the fork function inherits the file descriptor of the parent process. Here we have encountered a problem. At the same time, it will inherit the resource restrictions of the parent process and many other things.
6. Fork failure, which may be too frequent. It may also be that the process has too many sub-processes. The maximum value of a sub-process is child_max.
7. Take a good look at fork, vfork, and clone, especially their similarities and differences.
8. What is the difference between vfork and fork: vfork will not be copied, and it uses the address space of the parent process completely. It aims to call exec immediately after calling this function. Vfork will block the parent process. The child process that runs first is allowed only after the child process returns or exits. All modifications to the variables in the child process are synchronized to the parent process. They use the same space. If you call a further action that depends on the parent process before exec or exit is called, a deadlock may occur.
9. process Termination: exit, _ exit, _ exit (these two _ exit do not clean the buffer zone, called by exit), return in main, return in the last thread, the last thread calls thread_exit. Abnormal Termination: call abort to receive some signals and cancel the last thread.
10. zombie process: in UNIX, a process that has been terminated, but the parent process has not been aligned with the aftermath (obtain information about the termination process, release the resources it still occupies) is called a zombie process.
11. Zombie process avoidance: there are basically two methods: one is to call fork immediately in the Self-process, so that the sub-process of the process will be taken over by the INIT process. Another method is to use credit: single (sigchld, sig_ign (ignore this signal) to receive this signal. What should I do after the process ends? How can I get the ID of the sub-process?
12. If a process is terminated, the kernel sends a signal to the parent process: sigchld. Then, the parent process can call wait or waitpid in the signal processing area to query the termination status of the process. The PID value returned by these two functions. The input parameter returns the seed state. Wait is blocked until a process is terminated. Waitpid can specify the PID of the process to wait for, and can be set to block.
13. waittid provides more flexibility. wait3 and wait4 can obtain the resource information of sub-processes.
14. Exec does not create a new process, and the process id remains unchanged. exec uses a new program to replace the text, Data, heap, and stack segments of the current process.
15. When exec is executed, the file stream is not closed unless the flag fd_cloexec is set with fctl, but the directory stream is closed.
16. The system function calls three functions: fork, exec, and waitpid, which are blocking functions. You cannot call the system function to set the user ID or group ID.
17. Accounting records correspond to processes rather than procedures. In fact, it is a kind of regular statistics.
18. process time: You can use times to obtain three time periods, which are Wall time (function return), user time, system time, and sub-process time.

After a multi-process calls fork and the function returns, the parent process and child process are in different memory spaces, and they cannot access each other's memory.

The fork function returns 0 to the child process. If the parent process returns less than 0, the child process fails to be applied. If the value is greater than 0, the PID of the child process is successful.

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.