Basically I want to dynamically start some processes which may create their own children processes, also I want to kill a certain group of processes I just created whenever I want. One way I could think of is to start processes with a name(to distinguish as a group), then use pkill to kill them by the name. The question is how to start a process with a name so that I can use pkill to kill them by the name? I am open to other solutions as well.
Asked
Active
Viewed 4.1k times
1 Answers
21
How can I start a process with a different name?
bash -c "exec -a <MyProcessName> <Command>"
Then you can kill the process with:
pkill -f MyProcessName

Community
- 1
- 1

user2829759
- 3,372
- 2
- 29
- 53
-
10I'm trying this with nodejs and it doesn't work, process name is always `node`. I'm using this `exec -a myprocess node server.js`. I can't get anything by using `pidof myprocess` and `pgrep myprocess`. However when I try to find the name of the process by the process ID I get `node` – 11thdimension Jun 28 '17 at 19:58
-
2The same problem. -a does not set the name. no error but nor name. – Čamo Feb 23 '21 at 22:10