孤儿进程组

#include<sys/types.h>
#include<errno.h>
#include<stdio.h>
#include<fcntl.h>
#include<signal.h>
#include<unistd.h>
static void sig_hup(int);


static void pr_ids(char *);




int main(void )




{


char c ;
pid_t pid ;
pr_ids("parent");
if(( pid = fork()) <0 )
{


printf("fork error\n");
return  0 ;
}
/*
 *
 * parent 
 * sleep to let child stop itself then parent exits
 * */
else if ( pid > 0 )
{
sleep(1) ;


}
else {
// child 
pr_ids ("child");
signal(SIGHUP,sig_hup) ;// establish signal handler
kill(getpid(),SIGTSTP) ;// stop ourslf 
pr_ids("child");// this prints only if we're continue
if(read(0,&c,1) !=1 )
printf("read error from control terminal ,erro = %d\n",errno);
exit(0);
}





static void sig_hup(int signo)




{
printf("SIGHUP received , pid = %d \n", getpid());
return 0;


}


static void pr_ids(char *name)
{
printf("%s : pid = %d ,ppid = %d ,pgrp = %d ",name ,getpid(),getppid(),getpgrp());
fflush(stdout);
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值