- 论坛徽章:
- 36
|
本帖最后由 cokeboL 于 2011-05-19 17:38 编辑
回复 1# tq0fqeu - #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main()
- {
- pid_t pid;
- if( (pid = fork()) < 0){
- perror( "fork error: %m\n" ), exit(-1);
- }else if( pid > 0 ){
- while(1){
- printf( "parent zZZ..\n" );
- sleep(1);
- }
- }else if( pid == 0 ){
- sleep(3);
- printf( "parent pid: %d\nchild pid: %d\n", getppid(), getpid() );
- kill( getppid(), 40 );
- sleep(1); //刚发送完信号需要小下时间才到
- printf( "\nparent has been killed !\nnew parent is: %d\n", getppid() );
- pause();
- }
- return 0;
- }
复制代码- cokeboL@ubuntu:~$ a.out
- parent zZZ..
- parent zZZ..
- parent zZZ..
- parent pid: 4173
- child pid: 4174
- 实时信号 6
- cokeboL@ubuntu:~$
- parent has been killed !
- new parent is: 1
复制代码 |
|