如何获得通过setsid执行的过程中ID [英] how to get the ID of a process executed via setsid
问题描述
我正打算控制某些程序(如媒体播放器和外壳),通过web应用程序,
因为网页死每次用户访问它,我决定将Web应用程序打开的程序与 setsid
,然后webapp的时间内会通过管道进行通信。
I'm planning to control some programs (like a media player and a shell) via a webapp,
since the webpage die everytime the user visits it, I decided that the webapp will opens the program with setsid
and then the webapp will communicate with it through pipes.
注:我不能使用的nohup
becouse像的nohup的bash -i< fifoin> fifoout 2 - ;&放大器; 1安培;
自动停止。
Note: I can't use nohup
becouse something like nohup bash -i <fifoin >fifoout 2>&1 &
automatically stops.
使用 setsid
一切完美,但我不能杀死进程,因为我不知道派生进程的ID! ..所以,我怎么能retrive的 setsid
ED进程的ID?
With setsid
everything works perfectly, but I cannot kill the process since I don't know the ID of the forked process! ..So, how can I retrive the ID of the setsid
ed process?
我想是这样
setsid bash -i <fifoin >fifoout 2>&1
kill $!
kill $$
作为结果,两个杀
不工作,我不会用 PS -e
becouse我搜索ID不能杀死所有正在运行的的bash -i
外壳!
As result, both kill
don't work, I wont search the ID with ps -e
becouse I can't kill all the running bash -i
shell !
推荐答案
只有使用复杂的有些方法 strace的
来我的脑海。
Only somewhat intricate methods using strace
come to my mind.
如果您可以在不重定向标准错误做的:
If you can do without redirecting standard error:
read _ _ sid < <(2>&1 strace -esetsid setsid bash -i <fifoin >fifoout)
echo $sid
如果您需要重定向标准错误:
If you need to redirect standard error:
strace -o/tmp/filename -esetsid setsid bash -i <fifoin >fifoout 2>&1 &
sleep 1 # Hope 1 s is long enough
read _ _ sid </tmp/filename
echo $sid
这篇关于如何获得通过setsid执行的过程中ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!