Linux Process Control-general Linux technology-Linux programming and kernel information. The following is a detailed description. On the National Day, I went to the embedded linux training class. I spent a huge sum of 4500 yuan in tuition, and I am so distressed.
In October 6, the linux Process was controlled.
1. Obtain the process ID
# Include
# Include
Pid_t getpid (void); // return the caller's process ID
Pid_t getppid (void); // return the caller's parent process ID
Pid_t getuid (void); // return the user ID of the caller
Pid_t geteuid (void); // return the caller's valid user ID
Pid_t getgid (void); // return the caller's group ID
Pid_t getegid (void); // return the caller's valid group ID
2. fork Function
It is actually copying the current process.
# Include
# Include
Pid_t fork (void );
Return Value: The value is 0 in the sub-process, the value is the sub-process id in the parent process, and-1 is returned if an error occurs.
The lock set by the parent process. The child process does not inherit the lock. The warning pending for the sub-process is cleared. The pending Signal Set of the sub-process is set to null.
For example:
/* Myfork. c */
# Include
# Include
# Include
# Include
Int main (void)
{
Pid_t pid;
Pid = fork ();
If (pid <0 ){
Perror ("fork error ");
Exit (1 );
}
Else if (pid> 0) {/* in parent process */
Printf ("child process id = % d \ n", pid );
Return 0;
}
Else {/* in the sub-process */
Printf ("parent process id = % d, my id = % d \ n", getppid (), getpid ());
Return 0;
}
Return 0;
}
Today, I wrote so much, but there are still a lot of things to add in a few days.
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