How to return from shutdown command

D-Man dsh8290 at rit.edu
Mon Feb 12 11:06:26 EST 2001


On Mon, Feb 12, 2001 at 11:26:25AM +1100, Craig Findlay wrote:
| D-Man <dsh8290 at rit.edu> wrote:
| 
| >
| >If you have just shutdown the system, how is the script supposed to
| >continue running?  ;-)
| 
| shutdown -h +1 shuts the system down in 1 minute. Time enough to exit
| gracefully from my script if it would only return.

Maybe putting the call in a different thread/process?

Something like

pid = fork()
if pid != 0 :
	# must be the new child process
	exec( "shutdown -h +1" )
# this is the parent (original process)

cleanup()
sys.exit( 0 ) # exit normally


I believe the system() function is really just a nice pretty wrapper
around the whole fork-exec idiom that is convenient in the most common
case.  I also think that system() doesn't return until the child
process exits (I guess then that 'shutdown' doesn't exit in time).

HTH,
-D





More information about the Python-list mailing list