help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] get pid of exited process


From: Stas Sergeev
Subject: Re: [Help-bash] get pid of exited process
Date: Sun, 3 Jan 2016 20:10:38 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

03.01.2016 10:32, Eduardo A. Bustamante López пишет:
If the process died already, then the pid you're getting is no longer a valid
pid. Also, it could be the pid of a new and very different process.
Please note that the pids are not re-used, at least not so quickly.
OS will not assign the once-used pid to the new process, until all the
other possible pids are used too. So things like that should be safe,
especially if you raise the value of /proc/sys/kernel/pid_max to something
that really makes sense. I believe on 64bit machine you can raise
it to some value that will avoid the pid re-use forever.

If even with that in mind you want to proceed, you can do this:
Thanks! That's a nice trick that works well for me.

The reason I need this, is for the program-specific cleanup.
Programs usually create the pipes and sockets, embedding
the PID in their names. If such program crashes, the startup
script needs to do the cleanup. For that it needs to know the
pid of the program it was executing.
I think such scenario is valid and rather common, so I am a
bit upset bash does not have a native support for this.
But your trick is almost as convenient as the native support.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]