I want to write a unix shell script to run a command 3 times in every 80 seconds and write the every sequence in a different line in a text file. And also if the all results are 10 or more in a line I want to kill the process:
for example:
pstack <pid> | grep -c 'abcd'
5
pstack <pid> | grep -c 'abcd'
5
pstack <pid> | grep -c 'abcd'
5
//Nothing to do.
//after 80 seconds again it runs:
pstack <pid> | grep -c 'abcd'
10
pstack <pid> | grep -c 'abcd'
10
pstack <pid> | grep -c 'abcd'
10
kill -9 < PID> // because all three outputs are bigger than 10
also
the output file:
5 5 5
10 10 10
Note the if the output sequence is "10 10 11", "10 11 12" etc. then the process should be killed again. But if it is like "9 9 10" then no need to be killed.
What are you trying to achieve?
Sounds like an extremely hacky way to monitor a process. Couldn't you simply employ:
or a variation (
man bash
, /ulimitEnter)?That way a program could even possibly be more graceful in shutting itself down.
Note: since you suggest using
kill -9
without trying other signals, perhaps you imply that signals never get handled? In that case you can probably useulimit -i
(the maximum number of pending signals)Snippet