I am building a nodejs commmand line application that starts several detached child processes. Some of them are express severs listening to at a specified port. As I mentioned these processes are detached. How do i store information about these detached child processes like pid to kill them when the user wants.
I have tried writing them into a generic file which I later read to get the data.
Is there a better way?
You don't really have to keep track of all child process for terminating them. You can kill all the child process using their Process Group ID (PGID) .
PGID=$(ps opgid= "$PID" | tr -d ' ')
kill -- -$PGID
You will get parent process Id (PID) by
ps aux | grep "process_name" | awk '{print $2}'
In your case the process name will be "node"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.