how can I write this shell script in python?

Unix: How do I kill a shell script that executes multiple Python programs?

  • So here's my shell script: increment=1 terminating=512 while [[ "$increment" -lt "$terminating" ]] do     time python http://DoublePendulum.py 1 "$increment" 1 20000     increment=$((increment * 2)) done But I realized I did something wrong and tried to kill it. Unfortunately, I ended up having to kill each of the individual processes, as shown here: 282    10:45    top    283    10:45    kill 10026    284    10:46    top    285    10:46    kill 10031    286    10:46    top    287    10:46    kill 10030    288    10:46    top    289    10:46    kill 10033    290    10:46    top    291    10:46    kill 10036 is there a special name that the shell script goes by when calling "top"? I couldn't necessarily find it at first glance.

  • Answer:

    From your question, it seems like you're trying to kill the python processes that your script spawns, and that the script name is "http://DoublePendulum.py", and that you'd like them all dead at once. Try the following command: ps auxww | grep DoublePendulum | awk '{ print $2 }' | xargs kill In short: Verbosely list the running processes Look for the string "DoublePendulum" and only show us those lines Take each line in the output and print the contents of the second column (the process number) Pass each process number to the kill command BE CAREFUL running commands like this. You might try running ps auxww | grep DoublePendulum first to make sure that the stuff that displays is the stuff you want to kill. You also need to run the command either as the user running the process, or as root. Generally, ps and grep are great tools for finding specific processes, since it will print to the console and won't require you to quit and reopen things.

Isaac Meister at Quora Visit the source

Was this solution helpful to you?

Other answers

pstree -p will show you the tree of processes with the corresponding PID, you can kill the parent process

Gustavo Muslera

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.