I'm working on a supercomputer and have a shell script that will automatically schedule a bunch of jobs for me. Once the script is run, I can terminate manually with Ctrl+C. I was running the script from a unix screen session and terminated the screen, but the script is somehow still running and submitting jobs. It seems to be stuck in a loop and not ending, thus consuming precious core-hours.

I tried ps -u [user] but it doesn't show up. I know for a fact that it's still running in the background and just need to kill it.

Edit: uname -a gives the following result:

Linux blogin3 2.6.32-431.20.3.el6.x86_64 #1 SMP Thu Jun 19 21:14:45 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

So I guess the supercomputer is running Linux.

  • What OS (or UNIX version) are you running this on. What does ps -ef | grep [scriptname] show you? – EightBitTony Jul 17 '14 at 14:15
  • Try ps -f -u username. Then kill processid or kill -9 processid – Mark Plotnick Jul 17 '14 at 14:21
  • @EightBitTony @terdon I've edited the original post to reflect the new information. Also, ps -ef | grep [scriptname] gives something like this: [user] 38875 34136 0 09:20 pts/3 00:00:00 grep [scriptname]. – user1799323 Jul 17 '14 at 14:22
  • @MarkPlotnick The script name doesn't show up when I try ps -f -u [username] – user1799323 Jul 17 '14 at 14:23
  • 1
    Also, if it doesn't, please post the script. It might be that you're using a queue system and the script has added the jobs to the queue and has exited. That's why jobs are still being launched but you don't see the script itself. Another possibility is that you've connected to a different node on the server than you used last time. Depending on how the server is set up, it might assign sessions to nodes randomly. – terdon Jul 17 '14 at 14:39

This is hard to debug with the information you've provided but consider this:

$ cat foo.sh 
#!/usr/bin/env bash
while true
    echo yes; 

That's just a simple infinite loop. If I launch the script with ./foo.sh, I can find it in the output of ps:

$ ps aux | grep foo.sh
terdon   25568  0.0  0.0  10996  1424 pts/12   S+   16:19   0:00 bash /home/terdon/scripts/foo.sh
terdon   25982  0.0  0.0  10356   928 pts/11   S+   16:23   0:00 grep --color foo.sh

To kill it, the simplest approach would be to use pkill and its -f flag:

   -f, --full
          The pattern is normally only matched against the  process  name.
          When -f is set, the full command line is used.

So, try:

pkill -f foo.sh
  • I run the script from the command line using sh myscript.sh but ps aux | grep myscript.sh comes up with nothing except this: jdong 39034 0.0 0.0 103252 864 pts/3 S+ 09:32 0:00 grep myscript.sh where the time is the current time. And no matter what I put for the argument of ps, it will return something like that – user1799323 Jul 17 '14 at 14:33
  • @user1799323 that's very strange. Why are you so sure that the script is still running then? Also, you said "supercomputer", that can complicate things. Are you sure you've connected to the same node as your original session? – terdon Jul 17 '14 at 14:35

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.