fork() test for Linux API

<Abstract: Now to the implementation stage of docker, the underlying namespace and cgroup should be deeply understood. The API it calls is also slowly familiar. #include #include int main() { pid_t fpid; //int count = 0; fp...

Now at the implementation stage of docker,

the underlying namespace and cgroup should be deeply understood.

The API it calls is also slowly familiar.

#include <unistd.h>
#include <stdio.h>

int main() {
    pid_t fpid;
    //int count = 0;
    fpid = fork();
   
    if (fpid < 0) printf("error in fork!") ;
    else if (fpid == 0) {
        printf("I am child. Process id is %d\n", getpid());
    }
    else {
        printf("I am parent. Process id is %d\n", getpid());
    }

    return 0;
}




Copyright statement: The content of this article is contributed by Internet users voluntarily, and this community does not own the ownership and does not assume relevant legal responsibilities. If you find any content suspected of plagiarism in this community, please send an email to: [email protected] to report and provide relevant evidence. Once verified, this community will immediately delete the allegedly infringing content.

Use Yunqi Community APP, feel comfortable~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326112443&siteId=291194637