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.
Note: I can't use nohup
becouse something like nohup bash -i <fifoin >fifoout 2>&1 &
automatically stops.
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?
I tried something like
setsid bash -i <fifoin >fifoout 2>&1
kill $!
kill $$
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 !
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With