Python Forum
check process status and start if it stop linux
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check process status and start if it stop linux
#4
(May-16-2018, 11:44 AM)snippsat Wrote: I use schedule if shall to this from Python and not using OS schedule.
Example using psutil to scan processes running.
If process is running nothing happens,if not running will start it.
This check is done every 10-sec.
import schedule
import time, os
import psutil

def check_process():
    PROCNAME = "notepad.exe"
    for proc in psutil.process_iter():
        if proc.name() == 'notepad.exe':
            return True
    else:
        return False

def check_run():
    if check_process():
        print('Notepad is running')
    else:
        print('Notepad in not running')
        print('Start <notepad.exe>')
        os.startfile("notepad.exe")

schedule.every(.10).minutes.do(check_run)
while True:
    schedule.run_pending()
    time.sleep(1)
Here close Notepad a couple of times,and it will be restart again.
Output:
Notepad is running Notepad is running Notepad is running Notepad in not running Start <notepad.exe> Notepad is running Notepad is running Notepad in not running Start <notepad.exe> Notepad is running

Thank you for your answer
But I have another problem that, I cannot calculate exactly time when process success start(sometime it take too long, sometime very fast to start successful). So if I set schedule to check process,It case can happen.

EX: restart_process take 20 minutes, but all script have run about every 10 minutes >> So if process die, It not enough time to start.

How to deal with this case
Reply


Messages In This Thread
RE: check process status and start if it stop linux - by inspirer - May-17-2018, 01:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ''.join and start:stop:step notation for lists ringgeest11 2 3,822 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Use Python to start/stop a server service via a webform? oakleaf2001 0 2,216 Apr-04-2020, 06:14 AM
Last Post: oakleaf2001
  start and stop omxlayer playback dezmob 2 5,975 Jan-27-2020, 09:43 AM
Last Post: dezmob
  how to stop and start a script for 30 seconds laspaul 9 11,370 Jan-16-2020, 02:13 PM
Last Post: laspaul
  How to sharing object between multiple process from main process using Pipe Subrata 1 4,467 Sep-03-2019, 09:49 PM
Last Post: woooee
  Problem: Once I cancel the process my program will start working! Hadad 0 2,046 Jul-24-2019, 04:09 PM
Last Post: Hadad
  Linux: Automatically kill process with fixed exe path anddontyoucomebacknomore 4 4,230 Apr-22-2019, 07:35 AM
Last Post: anddontyoucomebacknomore
  What's the difference b/w assigning start=None and start=" " Madara 1 2,953 Aug-06-2018, 08:23 AM
Last Post: buran
  Can I Control loop with Keyboad key (start/stop) Lyperion 2 4,277 Jul-28-2018, 10:19 AM
Last Post: Lyperion
  win10 Service(script) start and stop hwa_rang098tkd 0 2,932 Jun-21-2018, 07:42 PM
Last Post: hwa_rang098tkd

Forum Jump:

User Panel Messages

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