Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8897377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:19:37+00:00 2026-06-15T00:19:37+00:00

I am trying to constantly monitor a process which is basically a Python program.

  • 0

I am trying to constantly monitor a process which is basically a Python program. If the program stops, then I have to start the program again. I am using another Python program to do so.

For example, say I have to constantly run a process called run_constantly.py. I initially run this program manually, which writes its process ID to the file “PID” (in the location out/PROCESSID/PID).

Now I run another program which has the following code to monitor the program run_constantly.py from a Linux environment:

def Monitor_Periodic_Process():

    TIMER_RUNIN = 1800
    foo = imp.load_source("Run_Module","run_constantly.py")
    PROGRAM_TO_MONITOR = ['run_constantly.py','out/PROCESSID/PID']
    while(1):
        # call the function checkPID to see if the program is running or not
        res = checkPID(PROGRAM_TO_MONITOR)
        # if res is 0 then program is not running so schedule it
        if (res == 0):
            date_time = datetime.now()
            scheduler.add_cron_job(foo.Run_Module, year=date_time.year, day=date_time.day, month=date_time.month, hour=date_time.hour, minute=date_time.minute+2)
            scheduler.start()
            scheduler.get_jobs()
            time.sleep(TIMER_NOT_RUNIN)
            continue
        else:
            #the process is running sleep and then monitor again
            time.sleep(TIMER_RUNIN)
            continue

I have not included the checkPID() function here. checkPID() basically checks if the process ID still exists (i.e. if the program is still running) and if it does not exist, it returns 0. In the above program, I check if res == 0, and if so, then I use Python’s scheduler to schedule the program. However, the major problem that I am currently facing is that the process ID of this program and the run_constantly.py program turns to be same once I schedule the run_constantly.py using the scheduler.add_cron_job() function. So if the program run_constantly.py crashes, the following program still thinks that the run_constantly.py is running (since both process IDs are same), and therefore continues to go into the else loop to sleep and monitor again.

Can someone tell me how to solve this issue? Is there a simple way to constantly monitor a program and reschedule it when it has crashed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:19:38+00:00Added an answer on June 15, 2026 at 12:19 am

    There are many programs that can do this.

    On Ubuntu there is upstart (installed by default)

    Lots of people like http://supervisord.org/

    monit as mentioned by @nathan

    If you are looking for a python alternative there is a library that has just been released called circus which looks interesting.

    And pretty much every linux distro probably has one of these built in.

    The choice is really just down to which one you like better, but you would be far better off using one of these than writing it yourself.

    Hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a classic ASP application that I've been constantly trying to modularize. Currently,
Im trying to grab all data(text) coming from a URL which is constantly sending
I am trying to use priority_queue, and program constantly fails with error message HEAP
i am trying to imitate the sample given with using autofac, but constantly getting
i'm trying to run Redmine using rubyEE, but I am constantly facing some action_controller
I am trying to replace an Image URL which changes constantly. Image URL: src=/images/previews/logo-15-hp.jpg
Here's what I'm trying to do. I have a sprite that is constantly scaling
I've been trying to write a program in C++ that will monitor running processes
My program is a visualizer that is constantly updating the display. I am trying
I'm developing an application with BLE and am trying to constantly scan every known

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.