Demo Code to Fork the Child Process

Child process can be created by POSIX function fork(), and below is the demo code.

pid = fork();

if (pid == 0) {
    /* processing of child process */
} else if (pid < 0) {
    /* parent process: handle errors */
} else {
   /* parent process: the parameter of pid is the ID of forked child process */

And also, parent process could call function wait() to wait for finish of child process, instead of processing in the second return of function fork().



Fill in your details below or click an icon to log in: 徽标

You are commenting using your account. Log Out /  更改 )

Google photo

You are commenting using your Google account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理