last day (15 days later) » 

3:12 AM
2
Q: How to kill a stale process

AndyI run transcoding on Ubuntu server and sometimes the process goes stale and provides no output but ps aux shows process is still running - but with stale CPU usage I can get the CPU usage with the following command(ffmpeg process i was working with has process id 4416: ps aux | grep -v grep | ...

 
How can you determine it's stale? Low CPU usage? If so I'd indeed use cron for the job and grep for 'ffmpeg'. Then parse line per line and check if it's stale. If it is, grep the PID and kill. I'd be happy to whip up a script for that.
 
Sometimes its low, sometimes normal. In both cases, if you keep greping ps aux for that process, CPU usage is the same. I kill it manually, it just happens too often now and i'd be glad to have a cron to check and kill such processes.
 
Check my answer, the second one in particular. You can set a tolerance as you wish in awk, you can even supply it as an argument, if you please.
 
Can you please shed some light on what awk '{ if ($3 > 0.1) { system("kill " $2); } }' does to a stale process with CPU usage for 34.5 lets say?
 
Yes, it checks if the third column has a value lower than 0.1 (it's still higher in the code you supply but I changed it), if it does it gets killed. That is, if the value in the third column determines whether it's stale or not. - So with the updated code: a 34.5 would not get killed.
Try to define as precisely as possible, when you call a process stale. Which column makes you say, this is a stale process (which column and which value it ranges in).
 
3:12 AM
So i know for a fact that lets say, stream 1 has died. I check it with the following command:
 
Ok so, can you say a process is stale by having a single look at it?
Or do you need a couple ps aux to conclude that?
 
live transcding dies, i logi n to the server and check the process
each time i check a properly working process the CPU usage jumps from 30 to 50, the stale process returns same CPU usage for each ps aux request
 
ok so say we do a couple requests
the ones who always have the same CPU usage are stale?
am I correct?
 
Yes, correct!
 
Can they vary a little or are they exactly the same?
Either way, I'll have the script ready in about 10 minutes
 
3:17 AM
exactly the same, no matter how many minutes/hours i kept analyzing it - it doesnt change
fantastic, thank you so much
 
3:40 AM
I get this:
awk: cmd. line:2: FNR==1 { index = $1 }
awk: cmd. line:2: ^ syntax error
awk: cmd. line:4: cpu[$2][index] = $3
awk: cmd. line:4: ^ syntax error
awk: cmd. line:4: error: invalid subscript expression
awk: cmd. line:12: if (j >= index) {
awk: cmd. line:12: ^ syntax error
 
yea I'm seeing it too
which is really odd but I'll debug it in a second
seems to be some basic stuff I'm missing here, how can I not know how to assign a variable in a language I use on a daily basis lol
problem seems to be the variable name "index"
should be fixed now
Yes it definitely works now, at least on my machine
problem is I tested with bash and I killed all my bash jobs lol
 
3:58 AM
lol
do i just grab the new script from the answer page?
 
I also added a few lines which will prevent a new job from being killed
yea
if you wish to be certain I can give you a few debug lines
comment out the system line
and add: "print "kill " pid
else { print "no kill " pid }
and add "print cpu[pid][j]" right after ++j
then you'll have a good view on the mechanics
it will print the cpu usage of all ps aux requests followed by "kill" or "no kill"
Anyway, let me know if there are issues and don't forget to accept and upvote if the answer is to your liking. But right now I'm heading to bed!
 
O yes! worked like a charm!!!
Thank you very much
 
No problem!
What else to do on my birthday, haha
 
4:26 AM
Drink beer!!
:D
Happy Birthday!
How would i extend the window of ps aux compares?
It kills valid processes too....
 
4:58 AM
no kill 13653
48.2
48.2
48.2
kill 11100

no kill 13656
44.0
44.0
44.0
kill 11696
54.5
54.5
54.5
kill 11102
55.3
55.3
55.3
kill 11698

no kill 13659
62.8
62.8
no kill 11700
no kill 11094
41.4
41.4
41.4
kill 11095
65.2
65.2
no kill 10504
61.4
61.4
61.4
kill 11702
40.1
40.1
40.1
kill 11548
66.0
66.0
66.0
kill 11107
0.0

no kill 13650
45.7
45.7
45.7
kill 11098
46.7
46.7
46.7
kill 11109
how do extend time between ps aux grabs?
 
 
13 hours later…
5:59 PM
Hi there, I am just interrupting you to make a shameless advertisement for my last blog article, where I discuss how to implement complex treatments in shell programs! I would love to hear your feedback! – unix-workstation.blogspot.de/2015/04/… Have a nice day!
 

last day (15 days later) »