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

2
  • 3
    Killing the parent of command doesn’t work?
    – HBruijn
    Dec 21, 2017 at 7:42
  • unfortunately, i can't find parent command. pstree doesn't work on the unix system i am using
    – Sam Gold
    Dec 21, 2017 at 9:40

1 Answer 1

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.

2
  • 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, 2017 at 9:42
  • @SamGold, ouch. It that case you could use command ps -o ppid= -p <PID>. Where <PID> - PID of process running in loop. Dec 21, 2017 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .