Today, I learned how to create a process in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. Today, I feel a little bit about the fork () function. You can create a process.
The following is the simplest code. The output result is the irregular alternation of This is child process and This is process,
It indicates that the two processes have the opportunity to run in the same time period.
Void main (){
Int I;
If (fork () = 0)
{
/* Sub-process program */
For (I = 1; I <1000; I ++) printf ("This is child process \ n ");
}
Else {
/* Parent process program */
For (I = 1; I <1000; I ++) printf ("This is process \ n ");
}
}
Fork () can return two values at a time. This feature has never been encountered before, so it is very special,
If-1 is returned, the Process Creation fails;
If the return value is 0, the sub-process is returned;
If a positive value is returned, it indicates the parent process.
I suddenly thought of a problem here. In this case, can I run a program on the front desk while running a program on the background at the same time? Can I steal the game password? The front-end creates an interface identical to the game login interface, while the back-end records user input and transmits key information such as passwords to our mailbox through certain means, this is a program for account theft.
The sub-process and the parent process are two different processes. Channel knowledge is required for communication. Today, no more. I have found this article. I have no time to read it. Now I want to go to it. < <Mao summary> > It's depressing. Come back to study at night!
There is such an idea, but a lot of things are not yet, but you have to learn slowly and take a long time, everything will be fine!
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