how to get the ID of a process executed via setsid

后端 未结 2 612
我寻月下人不归
我寻月下人不归 2021-01-18 16:01

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 ope

相关标签:
2条回答
  • 2021-01-18 16:01

    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
    
    0 讨论(0)
  • 2021-01-18 16:26

    You still need to background the process with &, otherwise it'll be running in the foreground blocking the following lines from even attempting to execute.

    setsid bash -i <fifoin >fifoout 2>&1 &
    kill $!
    
    0 讨论(0)
提交回复
热议问题