【发布时间】:2019-11-18 18:04:24
【问题描述】:
我不确定如何使用 tcsetpgrp() int tcsetpgrp(int fildes, pid_t pgid_id); ,我想将前台组 pid 设置为孩子的新组 pid,这样当我键入 control-C 时,它只会杀死我的子进程终端,而不是后台终端。 (我认为目前,父组pid与shell的前台gpid相同)
// we are in the child process
// check the foreground process group id.
pid_t fore_pgid = tcgetpgrp(0);
printf("the foregroud pgid is: %d \n", fore_pgid);
// change the foreground process group id to the redefined child process's group pid.
tcsetpgrp(0, child_gpid);
fore_pgid = tcgetpgrp(0);
printf("the foregroud pgid is: %d \n", fore_pgid);
结果:程序卡在了tcsetpgrp(0, child_gpid);这一行
因为在那之后它没有打印出一些字符串。
请注意,以上只是我的想法,可能不正确;我不知道如何只杀死我的子进程,而不是后台 shell。如果你知道如何做到这一点,请帮助我。 提前致谢!
【问题讨论】:
标签: c operating-system