0

I'm logged into a remote server (server is CentOS, I'm on Ubuntu). I executed the following command:

nohup bash script.sh > log.txt &

script.sh contains, simplified, this content:

for q (some condition that will trigger about 60 times)
do
sed (change config file for some other program depending on q)
execute some other program (each call of this other program takes about 25 minutes)
done

Unfortunately I realized there was a small error in the other program. I fixed it with no trouble but I am having trouble actually killing this script so I can start it over with the fixed other program. When I did the nohup bash script.sh at the beginning, it popped out a number 1946, which I assume is the pid for script.sh. I did:

pkill 1946

That stopped the OTHER PROGRAM that script.sh calls (I can tell from the logfile it creates). But then, script.sh calls the next iteration of the other program. I can tell because the logfile that script.sh makes tells me, and also, the other program uses my GPUs, which I can monitor with nvidia-smi. I don't see script.sh in "top" but I do see the program it keeps calling. I have been able to get around this by the following:

while true
do
sleep 1
pkill (the other program)

After a minute or so it kills all the iterations that script.sh would do. But this is not an elegant way to do it.

If I was physically at where the server is (I do go sometimes), I do the following in the same situation:

pkill -u (me)

This kills everything I'm doing. I just log back on and start over, no big deal. It happens a lot while I debug the other program. But right now I'm logged in via a command like this executed on the server:

ssh -r (server) (my home)

So if I do that, it will kill my connection to the server. Obviously I don't want to do that.

Normally I would be a bit more adventurous and try things before I run here to ask, but I am playing it safe. I don't want to kill my ssh connection. How can I properly kill script.sh elegantly? (Yes, I did try simply doing "pkill script.sh" or "kill script.sh", it did nothing).

2

ps -edf | grep script.sh

Kill the processes. Focus on the primary process that is spawning the rest first. Then work your way back through all the child processes.

And then kill -9 the processes #

Or

killall script.sh

  • Unfortunately that doesn't seem to be working. When I do ps -edf, I get this result: 505 9374 2065 0 17:54 pts/1 00:00:00 bash runner.sh runner.sh being my script. I try pkill 9374, pkill 2065, pkill 505, pkill runner.sh, nothing actually kills it. – iammax Jul 5 '17 at 22:10
  • Pkill expects a name and kill expects a process # – washingon Jul 5 '17 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.