How to create two processes ~~~~~~ -- Linux general technology-Linux programming and kernel information. The following is a detailed description. Oh, sorry again...
I read a book where the parent process creates two sub-processes, which are written as follows:
Int main ()
{
Pid_t p = fork ();
Pid_t q = fork ();
Switch (p ){.......}
Switch (q ){.......}
}
I think there is a problem with this writing. I understand that the process created by q has not only been created in the parent process main, but also in the process created by p. In this case, there should be four process spaces: p in main, q in main, q in p.
So I think if we want to create two sub-processes with the same status in a parent process, we should write this:
Int main ()
{
Pid_t p = fork ();
If (p> 0)
{
Pid_t q = fork ();
Switch (q ){.......}
}
}
In this way, the parent processes of p and q2 are both main and have the same status.
I don't know if I understand this, right ???
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