On 2018-02-10 22:36, Bernhard Voelker wrote:
On 02/10/2018 10:29 PM, Carlos E. R. wrote:
Is it possible to get the PID of the previous command launched and finished?
Example:
fetchmail .... echo "Posible PID of fetchmail was: $!"
Well, the value I get I know it was not the PID. The documentation says that "$!" gets the PID of the previously backgrounded process, so it is not what I want.
The crucial term for "$!" is: "background process".
Yes.
You send a process to background if you start it with "&" a the end.
Yes, I know.
$ sleep 60 &
$ echo $! 14100
So if you need the PID of the previously launched and finished process (whatever this may be good for),
To be able to read all it did in its log entries, differentiating from other instances that had a different PID (and some running at the same time, concurrently, so I can not simply "tail -f" the log).
then you could e.g. do:
sleep 10 & # send process to background pid=$! # get its PID wait $pid # wait for the process to terminate rc=$? # get the exit status of the process echo "PID: $pid, exit status: $rc"
Ah, interesting, thanks. -- Cheers / Saludos, Carlos E. R. (from 42.2 x86_64 "Malachite" at Telcontar)