I would like to use a Python script to periodically check to see if a
program is still running and if it isn't I want to start it up. Could
someone point me on the right path? Thanks in advance.
Kamuela 5 7167
Kamuela Franco <ka******@veriz on.net> writes: I would like to use a Python script to periodically check to see if a program is still running and if it isn't I want to start it up. Could someone point me on the right path? Thanks in advance.
Search the ASPN Python Cookbook for "watchdog" -- I remember a recipe
there (search c.l.py with Google Groups too, of course).
John
Kamuela Franco <ka******@veriz on.net> wrote in message news:<pa******* *************** ******@verizon. net>... I would like to use a Python script to periodically check to see if a program is still running and if it isn't I want to start it up. Could someone point me on the right path? Thanks in advance.
Kamuela
1st, which OS are we talking about ? *IF* we're talking about
Linux/Unix/FreeBSD, then it only takes a few lines:
import os
import string
f = os.popen( 'ps -ax' )
s = f.readlines()
if string.find( s, 'target_pgm' ) > -1:
#### we found it, so do something....
If we're talking about Windows, then this would work using the
Cygwin utils for ps or one could try Pythonwin. Mark has ported
many Windows APIs, so it would be a little more involved, but
straight-fwd. HTH....Jet
Hello Jetman, I would like to use a Python script to periodically check to see if a program is still running and if it isn't I want to start it up. Could someone point me on the right path? Thanks in advance. If we're talking about Windows, then this would work using the Cygwin utils for ps or one could try Pythonwin. Mark has ported many Windows APIs, so it would be a little more involved, but straight-fwd. HTH....Jet
There are always the pstools from sysinternals
( http://www.sysinternals.com/ntw2k/fr.../pstools.shtml)
HTH.
Miki je*******@hotma il.com (The Jetman) wrote... 1st, which OS are we talking about ? *IF* we're talking about Linux/Unix/FreeBSD, then it only takes a few lines: import os import string f = os.popen( 'ps -ax' ) s = f.readlines() if string.find( s, 'target_pgm' ) > -1: #### we found it, so do something....
I don't understand why so many people do this, grepping the process
list for strings is a terribly unreliable way of testing whether a
program is alive, especially when you don't have control of the
process list (eg. customer computers).
Might I suggest a modification to the procedure in my last post? Give
it an argument and pass that argument to ps' "-C" switch. Then test
for process existance with something like:
if len(get_process _ids('yourbin') ) == 0:
# check for repeated crashes.
# restart the server.
There are a multitude of programs for every imaginable OS to do this
for you already. Have you looked at them? There's one at http://cr.yp.to/, and many more at http://freshmeat.net/.
David.
"The Jetman" <je*******@hotm ail.com> wrote in message
news:a3******** *************** ***@posting.goo gle.com... 1st, which OS are we talking about ? *IF* we're talking about Linux/Unix/FreeBSD, then it only takes a few lines: import os import string f = os.popen( 'ps -ax' ) s = f.readlines() if string.find( s, 'target_pgm' ) > -1: #### we found it, so do something....
If the process id is known, use "kill -0 pid" to check if the process is
still running.
Additional, you may need to check if it's coring even the return value of
the kill command is not 0. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mark |
last post by:
Thanks.
|
by: ransoma22 |
last post by:
I developing an application that receive SMS from a connected GSM
handphone, e.g Siemens M55, Nokia 6230,etc through the data cable.
The application(VB.NET) will receive the SMS automatically, process and
output to the screen in my application when a message arrived. But the
problem is how do I read the SMS message immediately when it arrived
without my handphone BeEPINg for new message ? I read up the AT
commands, but when getting down...
|
by: Johhny |
last post by:
Hello,
I am currently looking to write a utility in python that will monitor
the statis of a RAID card within linux. The card in Question is the LSI
SAS1064 as the tools provided by the vendor to monitor the software
does not suit our requirements.
However I am unsure how to convert dmidecode information like so :
Handle 0x0025
|
by: |
last post by:
Greetings.
In an effort to get python2.4 on my Centos 3.7, I installed the python
bootstrap rpm. This installed 2.4 alongside 2.2 and updated yum to 2.4.0.
Oddly, it didn't create a symlink 'python' for either 2.2 or 2.4. I also
get a series of troubling dependency errors when I run yum update. Below is
the output of the bootstrap install, which includes both a failure early on
(possibly related to alternatives and/or the symlink?)...
|
by: tshad |
last post by:
What would be a good way to check programmatically whether a service was
running?
We have a service that dies periodically and I need to check to see if this
service is running. I know how to check to see if the status is in stopped
or running mode. But that doesn't tell me if it is actually running.
I need to know this so that if it happens I can programmatically start the
same service on another machine.
| |
by: wardm |
last post by:
I have created a Dict object in a C++ App that calls (embedded) Python
functions.
The Dict is to be used to pass variable data between the C++ App and the
python functions.
However I cannot get the Python functions to 'see' the Dict created in the
C++ App.
The C++ app creates the Dict using the following functions:
|
by: yaru22 |
last post by:
I'd like to create a program that validates bunch of urls against the
w3c markup validator (http://validator.w3.org/) and store the result in
a file.
Since I don't know network programming, I have no idea how to start
coding this program.
I was looking at the python library and thought urllib or urllib2 may
be used to make this program work.
|
by: Mark Tarver |
last post by:
How do you compare Python to Lisp? What specific advantages do you
think that one has over the other?
Note I'm not a Python person and I have no axes to grind here. This is
just a question for my general education.
Mark
|
by: RossGK |
last post by:
I'm a newbie to python threads, and playing with some simple client
server stuff and lots of print statements.
My server thread launched with
self.worker = WorkerThread(self)
completes an interaction and then if I check on it's status with
print "Status:", self.worker I get Status none
A client thread behaves differently. Launched as
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |