1

We are connecting to the same host via the same user. So, only our sessions/tty are different. If one of us starts a for loop such as:for i in *; do command $i; done, I don't know how to stop it. All I can do is search for the command name in ps aux and kill that instance of the command. But the for loop keeps going on, thus generating another command process.

How can I find that for loop and kill it?

Thank you, Sam

Sam Gold
  • 11
  • 2
  • 3
    Killing the [parent](https://superuser.com/questions/150117/how-to-get-parent-pid-of-a-given-process-in-gnu-linux-from-command-line) of `command` doesn’t work? – HBruijn Dec 21 '17 at 07:42
  • unfortunately, i can't find parent command. `pstree` doesn't work on the unix system i am using – Sam Gold Dec 21 '17 at 09:40

1 Answers1

1

You could try to use pstree to find shell where for executed.

For example, I run loop with command for i in {1..1000}; do sleep 5; done, then I do pstree -p | grep sleep, see output | -sshd(29695)---sshd(29707)---bash(29709)---sudo(29735)---bash(29736)---sleep(3843). Then kill -9 29736 kill shell, where loop executed and stop it.

Alexander Tolkachev
  • 4,608
  • 3
  • 14
  • 23
  • i am using tru64 system, and `pstree` isn't available here. Is there any other way to find parent process or the shell where `for` executed? – Sam Gold Dec 21 '17 at 09:42
  • @SamGold, ouch. It that case you could use command `ps -o ppid= -p `. Where - PID of process running in loop. – Alexander Tolkachev Dec 21 '17 at 09:45