I have a bunch of commands that I start with a
start.sh script, storing their PID. Then later, I want to stop them with a
stop.sh run at the user's convenience.
Watch the trap:
- I run
start.shtoday, which stores in a file the PIDs
- I forgot stopping my processes. And a week after, I rebooted my computer.
- I run the
stop.shscript, now. It attempts to kill the tasks with PIDs
15002, reading them without thinking from the file.
=> These tasks, if some happen to have these PIDs on my new rebooted system, are no longer the ones I started by my
start.shscript, and I will put my system into an unknown state.
How, when I catch first the PID of a process with a
$$ in a Linux script, may I gather other information to ensure I can have no confusion with another task of same PID that could appear in the future?
Gathering PPID, for example, or start date/time, or something that ensures some kind of "universal uniqueness", if I can write this.. ?
How do you gather process information and how do you kill it without confusion?