I have a problem with some zombie-like processes on a certain server that need to be killed every now and then. How can I best identify the ones that have run for longer than an hour or so?
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Stop child process when parent process stops
- Error building gcc 4.8.3 from source: libstdc++.so
You can use
bc
to join the two commands in mob's answer and get how many seconds ellapsed since the process started:edit:
Out of boredom while waiting for long processes to run, this is what came out after a few minutes fiddling:
If you put this on your path and call it like this: sincetime
it will print the process cmdline and seconds since started. You can also put this in your path:
And than if you run:
where patterns is a string or extended regular expression, it will print out all processes matching this pattern and the seconds since they started. :)
Perl's Proc::ProcessTable will do the trick: http://search.cpan.org/dist/Proc-ProcessTable/
You can install it in debian or ubuntu with
sudo apt-get install libproc-processtable-perl
Here is a one-liner:
Or, more formatted, put this in a file called process.pl:
then run
perl process.pl
This gives you more versatility and 1-second-resolution on start time.
In case anyone needs this in C, you can use readproc.h and libproc:
do a
ps -aef
. this will show you the time at which the process started. Then using thedate
command find the current time. Calculate the difference between the two to find the age of the process.Came across somewhere..thought it is simple and useful
You can use the command in crontab directly ,
or, we can write it as shell script ,
And call it crontab like so,
stat -t /proc/<pid> | awk '{print $14}'
to get the start time of the process in seconds since the epoch. Compare with current time (
date +%s
) to get the current age of the process.