Process creation analysis under Linux

Source: Internet
Author: User

Actual User: Indicates who you are, who is running it, used to identify information eg: ID card, invitation status, non-member

Valid users: Whether a resource has some kind of permission, the process may access some resources, ordinary users can not bear, identity changes to access resources

For example: Under the Linux system, the root user or the ordinary user can use the passwd command to modify the password, change the password mainly by modifying etc files to achieve, and shadow file permissions all empty, only Root has permission to modify this file. Therefore, when the ordinary user executes the passwd command, its privileges are improved in a flash, and run with owner privileges.

Guess the result of the run, will print a few messages??

#include <stdio.h> #include <unistd.h> #include <sys/types.h>int main () {         int i=0;        pid_t id;         for (; i<2;++i)          {                id=fork ();                 if (id==0) {/ /child                         printf ("pid: %d,ppid: %d\n", Getpid (), Getppid ());                 }                 else if (id>0) {//father                          printf ("pid: %d,ppid: %d\n", Getpid (), Getppid ());                 }        }         return 0;}

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7E/AD/wKioL1cHLsfgIX6AAAAnxBuClHU770.png "style=" float: none; "title=" QQ picture 20160408115214.png "alt=" Wkiol1chlsfgix6aaaanxbuclhu770.png "/>

The running result shows that the child process is created with fork () and the same program as the parent process is executed (but different code branches may be executed: if condition judgment shunt)

The back of the Ppid for 1 showed that they had become orphans and were adopted by the process 1th.

#include <stdio.h> #include <unistd.h> #include <sys/types.h>int main () {         int i=0;        pid_t id;         for (; i<2;++i)          {                id=fork ();                 if (id==0) {/ /child                         printf ("pid: %d,ppid: %d\n", Getpid (), Getppid ());                 }                 else if (id>0) {//father                          printf ("pid: %d,ppid: %d\n", Getpid (), Getppid ());                 }        }         printf ("pid: %dhello\n", Getpid ());         return 0;}

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7E/B0/wKiom1cHLhnTJIPdAAAqPArGxd4865.png "style=" float: none; "title=" QQ picture 20160408115909.png "alt=" Wkiom1chlhntjipdaaaqpargxd4865.png "/>


This article is from the "Small Stop" blog, please be sure to keep this source http://10541556.blog.51cto.com/10531556/1761685

Process creation analysis under Linux

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.