linux waitpid源码分析,linux wait与waitpid函数的深入分析(国外英文资料).doc

linux wait与waitpid函数的深入分析(国外英文资料)

linux wait与waitpid函数的深入分析(国外英文资料)

The in-depth analysis of Linux wait and waitpid functions

There are already 2050 reading of the 2010-9-3020:1| personal category: the LINUX system | keyword: waitpid LINUX function wait subprocess fork zombie

A) system calls wait

1) overview

The wait function's prototype is: pid_t wait (int * status)

When the process exits, it send a SIGCHLD signal to the parent process, always ignore the SIGCHLD signal by default, the process state remain in memory until the parent process USES wait function status information collection, will clear the information.

Waiting for a subprocess to terminate with wait is called the recovery process.

When the parent forget to use the wait () function to wait for terminated the child, the child will enter a state of no parent, the child process is a zombie process.

Wait () and fork () form a complete set, if you are using the fork () before calling wait (), wait () returns a value of 1, under normal circumstances the wait () return values for PID of the child process.

If the parent process is terminated first, the child process will continue normally, except that it will be inherited by the init process (PID 1), which is captured by the init process when the child process terminates.

2) the formation of zombie processes

The source program is as follows:

# include < sys/types. H >

# include < sys/wait. H >

# include < unistd. H >

# include < stdlib. H >

int

The main ()

{

Pid_t PC, pr;

PC = fork ();

If (PC < 0)

Printf (" error ocurred! \ n ");

The else

If (PC = 0)

This is child process with pid of % d \ n, getpid ());

}

The else {

Sleep (20);

This is partent with pid of % d \ n, getpid ());

}

The exit (0);

}

C compiler zombie.

GCC zombie. C - o zombie

Run the generated program

. / zombie

Also check the process status of the zombie

Ps - C zombie - o ppid, pid, stat, CMD

PPID PID STAT CMD

24233 26056 S +. / zombie

26056 26057 Z + [zombie] < defunct >

After 20 seconds, see the results of the program, as follow

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值