如何设置Shell脚本的进程组 [英] How to set process group of a shell script

查看:337
本文介绍了如何设置Shell脚本的进程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置Shell脚本的进程组?我也希望所有子进程都在同一个进程组中

我期望与C语言中的setpgid()类似.

解决方案

正如 PSkocik指出,可以运行在大多数外壳程序中,通过激活作业控制(监视模式")来在其自己的进程组中进行处理.

(set -m; exec process_in_its_own_group)

Linux具有 setsid 实用程序,该实用程序运行在自己的会话(使用进程组中运行它更强大 setpgrp ,但这可能对您有用.

如果要将进程放置在现有组中而不是在其自己的组中(即,如果要使用setpgid的全部功能),则没有通用的Shell实用程序.您必须使用C/ Perl /…

How to set process group of a shell script ? Also I want all the child process to be in the same process group

I expect something similar to setpgid() in C.

解决方案

As PSkocik points out, it is possible to run a process in its own process group, in most shells, by activating job control ("monitor mode").

(set -m; exec process_in_its_own_group)

Linux has a setsid utility, which runs the command passed as argument in its own session (using the eponymous system call). This is stronger than running it in its own process group à la setpgrp, but that may be ok for your purpose.

If you want to place the process in an existing group rather than in its own group (i.e. if you want the full power of setpgid), there's no common shell utility. You have to use C/Perl/…

这篇关于如何设置Shell脚本的进程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆