Thanks, I may use that as one of the example programs if you don't mind? Alan G.
----- Original Message ----- From: "Johan Geldenhuys" <[EMAIL PROTECTED]> To: "Alan Gauld" <[EMAIL PROTECTED]> Cc: "Python Tutor list" <tutor@python.org> Sent: Wednesday, November 16, 2005 8:12 AM Subject: Re: [Tutor] new topic draft > Alan, > > You may remember that I asked questions on killing a process, a while > back, > > Sice this is relatedto the tutorial that yu are writing, this was the > best solution that worked for me to killa process for a command that > keeps on running like eg. 'tcpdump'. > > HTH > > Johan > BTW, There will a be many a felllow Pythonists that will benefit from a > tut like this, great work !! > > > Alan Gauld wrote: > >>I've just added an incomplete draft copy of my latest tutorial topic >>on using the Operating System from Python. The material that's >>there discusses the role of the OS and looks at file handling >>usng os/os.path/shutil etc. >> >>http://www.freenetpages.co.uk/hp/alan.gauld/tutos.htm >> >>If anyone would like to take a look and provide feedback on >>general direction/depth etc that'd be greatly appreciated. >> >>TIA, >> >>Alan G >>Author of the learn to program web tutor >>http://www.freenetpages.co.uk/hp/alan.gauld >> >> >>_______________________________________________ >>Tutor maillist - Tutor@python.org >>http://mail.python.org/mailman/listinfo/tutor >> >> >> > -------------------------------------------------------------------------------- > """ > This class will execute the command, let it run for 5 seconds and kill > the process. > > ::Author: Johan Geldenhuys > [EMAIL PROTECTED] > > ::Version: 0.0.1 > > ::Date last updated: 2005-11-03 > > ::Changes: > > :: TODO: Capture the output from line 41 to a file. > """ > > import os, signal, time > > class command(object): > > def __init__(self): > > pass > > > def kill(self, pid, signal=signal.SIGTERM): > try: > > print "trying to kill pid...", pid > os.kill(pid, signal) > #os.waitpid(pid, 0) > print "Killed %d"%pid > except: > print "couldn't stop process" > > def main(self, interface): > > self.interface = interface > self.pid = os.fork() > > if self.pid == 0: > > os.execvp('tcpdump', ['tcpdump', '-npi', self.interface]) > > print 'PID: ',self.pid > print 'Let it run for 5 seconds...' > time.sleep(5) > self.kill(self.pid) > > > if __name__ == '__main__': > print "starting test" > c = command() > c.main('eth0') > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor