Almost There - os.kill()

Delaney, Timothy (Tim) tdelaney at avaya.com
Mon Sep 24 07:48:38 EDT 2007


Always be careful with int() incase any of the values have a leading
zero - check the documentation for int() carefully.
 
Cheers,
 
Tim Delaney

________________________________

From: python-list-bounces+tdelaney=avaya.com at python.org
[mailto:python-list-bounces+tdelaney=avaya.com at python.org] On Behalf Of
Robert Rawlins - Think Blue
Sent: Monday, 24 September 2007 5:10 PM
To: 'Robert Rawlins - Think Blue'; python-list at python.org
Subject: RE: Almost There - os.kill()



Woops,

 

Spoke too soon, just wrapped them in int() and it works a charm :-D

 

Rob

 

From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk at python.o
rg] On Behalf Of Robert Rawlins - Think Blue
Sent: 24 September 2007 12:23
To: python-list at python.org
Subject: Almost There - os.kill()

 

Hello Guys,

 

Finally got around to sitting down to tidy up this script this morning
but I'm having a small syntax problem with os.kill() to kill a process
on my system. Here is the code:

 

def killApplication():

 

       pid = file('/var/lock/MyApplication.lock').read().strip()

       

       logging.info('Killing Application Process: %s' % pid)

 

       os.kill(pid, 15)

 

       logging.info('Application %s Killed' % pid)

 

As you can see if rips the PID from the lock file, which works fine as I
get log data which says 'Killing Application Process: 3079' exactly as I
would expect it too. However when I run this script I get the following
error:

 

Traceback (most recent call last):

  File "/pblue/new/Alive.py", line 50, in ?

    main()

  File "/pblue/new/Alive.py", line 47, in main

    doCheck()

  File "/pblue/new/Alive.py", line 43, in doCheck

    killApplication()

  File "/pblue/new/Alive.py", line 28, in killApplication

    os.kill(pid, 15)

TypeError: an integer is required

 

Which would suggest its passing those arguments in as the wrong data
types to the kill command. What is the best way to convert these?

 

Thanks guys,

 

Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070924/408c7a58/attachment.html>


More information about the Python-list mailing list