Python Forum
How to kill a bash script running as root from a python script?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to kill a bash script running as root from a python script?
#3
That is what I was attempting to do with this...
import psutil
# this kills the timelapse.sh script to stop taking pictures (didn't work)
PROCNAME = "timelapse.sh"
for proc in psutil.process_iter():
    # check whether the process name matches
    if proc.name() == PROCNAME:
        proc.kill()
But it did not work. The timelapse.sh script was still running after the python script ended, and I didn't get any errors letting me know that it failed to end the bash script. The only way I realized that it had failed was because there were still pictures being written to the SD card after the python script ended. And I verified this with "ps aux" and could still see the timelapse.sh process running.
I was thinking maybe because it is running in the background as root? I don't know. It needs to run as root because if I run the scripts as a user, and then SSH into the Pi while everything is running, it will cause the scripts to 'pause' until I end the SSH login session.

Gribouillis

Thank you!

That did the trick!

Simple, elegant, awesome! Big Grin
Reply


Messages In This Thread
RE: How to kill a bash script running as root from a python script? - by jc_lafleur - Jun-26-2020, 10:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 443 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Using a script to open multiple shells? SuchUmami 9 611 Apr-01-2024, 10:04 AM
Last Post: Gribouillis
  How to include one script into another? MorningWave 8 559 Mar-21-2024, 10:34 PM
Last Post: MorningWave
  kill python execution program lebossejames 0 258 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  ChromeDriver breaking Python script genericusername12414 1 346 Mar-14-2024, 09:39 AM
Last Post: snippsat
  using PowerShell from Python script for mounting shares tester_V 8 570 Mar-12-2024, 06:26 PM
Last Post: tester_V
  No Internet connection when running a Python script basil_555 8 687 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 560 Mar-10-2024, 07:24 PM
Last Post: Winfried
  Combine console script + GUI (tkinter) dejot 2 454 Feb-27-2024, 04:38 PM
Last Post: deanhystad
  How to receive two passed cmdline parameters and access them inside a Python script? pstein 2 372 Feb-17-2024, 12:29 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020