When you started learning system programming, you learned about the use of fork and recorded it for your own learning.
The fork function is used to create a new process,
#include # Include
#include
#include
int main(void)
{
pid_t pid;
Char *message;
int n;
pid = fork();
if (pid < 0) {
perror("fork Failed");
exit(1);
}
if (pid == 0) {
message = "This is the child \ ";
n = 3;
} else {
message = "This is the parent\ ";
n = 6 ;
}
for(; n > 0; n--) {
printf("%s",message);
Sleep(1);
}
return 0;
}
Program run result:
Return value: Subprocess return 0, the parent process returns the id of the child process, if it fails, it returns -1;
The fork function is called once but returns twice. The only difference between the two returns is that the return value of the child process is 0, and the parent The process return value is the process ID number of the new process. The reason to return the child process ID to the parent process is that because there can be more than one child process of a process, and no function allows a process to obtain the process ID number of all its child processes. The reason the fork function returns the child process to 0 is that a process will only have one parent process, so the child process can always call getppid to get the process ID of its parent process
: In the hardware management of ITDB, it is necessary to assign users to the hardware. This user wan
Environment: REDHAT 51. Check if VNC is installed: rpm -qa vnc-server vnc-server-4.1.2-9.el5
Today, Xiaobian is a beginner Linux developer to explain how to install Linux. Here Xiaobian
How Linux extends the XFS file system. There is extra space on the disk, so I want to extend the exi
Computer Technology: cacti Installation and Configuration
Linux learning: find command problem
Linux. How to install and uninstall the .run file
Bluemix virtual machine Docker runs container
Linux network based routing DHCP configuration
Linux remote login ssh password free
PCI device driver development under Linux
Command to view port occupancy in GNU/Linux
The small knowledge points used in the Linux system accumulate
How does Windows 10 add the right-click menu "Copy Path" option?
Libsasl2.so.2 can not be found, apache can not start
A brief summary of the SHIFT key skills in the system
Win7 system backup registry editor method
How to deal with the Win8 application flashback problem
Win10 enables hidden notification center (a brand new method)
Windows 8 system how to open and disable the administrator account method
How to find FlashPaper printer
How to organize the Win7 system Recent folder? How to clean redundant files of Win7 system?
Win8 system prompts no solution for installing any audio output device