【问题标题】:don't know how to use tcsetpgrp()不知道如何使用 tcsetpgrp()
【发布时间】: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


    【解决方案1】:

    我不确定我是否理解您要执行的操作。

    这是 IBM 所做的一个示例

    IBM Example of tcsetpgrp()

    【讨论】:

      猜你喜欢
      • 2021-11-21
      • 2021-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-13
      • 2010-12-05
      • 2012-08-23
      相关资源
      最近更新 更多