Is there something "more unique" than process id PID?
Hi there!
I have the problem that I want to identify a process reliably after some time (i.e., after weeks or even months) to check whether it is still running or not. This however seems rather difficult: I cannot check the PID, since PIDs are only unique during the lifetime of the process. The maximum PID value is 32767, so when more processes are launched during uptime, the PID counter wraps around, starting from the beginning again. You can easily verify this with a shell script: #!/bin/bash if test -r "$0"; then echo "pid=$$"; "$0"& fi; Name this 'wrap'. When launched, it will run until you remove/rename its file. While running, it repeatedly restarts itself, occupying a new PID. The output looks something like > ./wrap [...] pid=32765 pid=32766 pid=32767 pid=300 pid=301 pid=302 [...] I also cannot use a combination of PID and command, since the same program may have been relaunched, accidentally occupying the same PID. This is not very likely, but not impossible. Just see the 'wrap' script above. Especially since the process I want to watch is to be relaunched repeatedly, it is very likely that it will have a PID assigned that it used before. Is there something like a "totally unique" PID that's never reused during uptime? I guess a 64-bit number should be enough. Any suggestins? Thanks! |
You might look at PID, PPID, STIME and TIME in combination; have a look at what ps -ef shows you or ps -elf.
|
Quote:
|
Quote:
--- Quote:
I start a process 'foo' in the background (using bash syntax). > foo& [1] 4321 It's easy to test whether a process with such a PID exists: > kill -0 4321 && echo alive alive > kill -0 9999 && echo alive bash: kill: 9999 - No such process Now assume 'foo' terminates. The PID counter wraps around. Another 'foo' process is started, accidentally having the PID 4321 assigned. > kill -0 4321 && echo alive alive Even looking in the process table will tell me that it's 'foo' running with PID 4321. But The original process died. --- Any other suggestions? Thanks, Stefan |
Ah I see. Sorry, misunderstood you. Don't really know a good way to do this, but a quick-and-dirty way might be something like:
Code:
(starttime=$(date); touch $starttime-begun; foo; touch $starttime-finished) |
All times are GMT -5. The time now is 08:12 PM. |