简体   繁体   中英

Stop running python shell script from Mac terminal

I started my shell script using something like the following:

sh python3_start.sh

How do I stop this completely? If the process is already running and I do a cntrl + c it seems like it stops it but I don't know if it's not entirely killed in the background.

Run the script, while it is running type the following into a different terminal session

top

If you see the script running in there then it is, if not the script has stopped. You might want to put some temporary sleep timers in your script so you can be sure. To do this add this somewhere within your python code. Make sure you are also importing time as well.

time.sleep(30)

If you need to kill the script from terminal you can do this as well. To do this run the following command in a different terminal session.

kill -9 "pid next to script in top" 

Run the following command to list all processes and extract the ones that contain "python3_start.sh":

ps ax | grep -i python3_start.sh

then you can use the "pid" ("pid" is the number in the beginning of each line) and run:

kill "pid"

if the first command only produces something like this:

28952 s000  S+     0:00.01 grep -i python3_start.sh

then you don't have your script running in the background.

Change "python3_start.sh" in the first command to any process you want to see is running and follow the same steps to kill it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM