[英]don't know how to use tcsetpgrp()
我不確定如何使用tcsetpgrp() int tcsetpgrp(int fildes, pid_t pgid_id);
,我想將前台組pid設置為孩子的新組pid,這樣當我鍵入control-C時,它只會殺死我的終端中的子進程,而不是后台終端。 (我認為當前,父組pid與外殼的前台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。 如果您知道該怎么做,請幫助我。 提前表示感謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.