#!/usr/local/bin/perl # Author: Kevin P. Inscoe . # File: waken.pl # Date of creation: May 11, 2004. # Warranty: None expressed or implied. # License: The Open Software License. V1.1 http://www.opensource.org/licenses/osl.php # # OSI Certified Open Source Software. http://www.opensource.org/licenses/ # # Prerequisites: Perl 5.004 (minimum). require 5.004; # # Takes a unique command name as the parameter and awakens the process from a sleep # state by modifying the proc table file similiar to the Solaris prun command. Then # verifies the process is runnable. Tested with Solaris 8 only. # #Turn off Perl buffering $| = 1; use strict; use Proc::ProcessTable; use Solaris::Procfs qw(:procfiles writectl :control_codes :pcset_flags); # Variables my $ref = new Proc::ProcessTable; my ($proc, $newproc, $state, $newstate); # Check parameters for required if ( @ARGV < 1 ) { print "waken.pl usage:\n"; print "\n"; print "$0 process-match-name\n"; print "\n"; exit 0; } foreach $proc (@{$ref->table}) { next unless ( $proc->{cmndline} =~ m/$ARGV[0]/ ) && ( $proc->{cmndline} !~ m/$0/ ); # see if it is already sleeping $state = $proc->{state}; if ( $state ne "stop" ) { print "$0: INFO: pid $proc->{pid} not sleeping.\n"; print " state: $state\n"; exit 0; } # Pour some water on me... print "Awakening pid $proc->{pid} cmd-> $proc->{cmndline}...\n"; # I could not get this to work at all... # writectl($proc->{pid},\&PCKILL,\&SIGCONT,\&PCRUN,\&PCNULL) or warn "Can't wake process $proc->{pid}: $!\n"; my @cmd = ("/bin/prun",$proc->{pid}); my $rc = 0xffff & system @cmd; if ( $rc > 0 ) { if ( $rc == 0xff00 ) { print "$0: ERROR: prun: $!\n"; exit -1; } if ( $rc > 0x80 ) { print "$0: ERROR: prun: non-zero exit of $rc\n"; exit -1; } if ( $rc & 0x80 ) { $rc &= ~0x80; print "$0: ERROR: prun: coredump from $rc\n"; exit -1; } print "$0: ERROR: prun: signal received from $rc\n"; exit -1; } print "Checking, please wait...\n"; sleep 3; # Is the patient asleep yet? my $newref = new Proc::ProcessTable; foreach $newproc (@{$newref->table}) { next unless ( $newproc->{pid} eq $proc->{pid}); $newstate = $newproc->{state}; if ( $newstate eq "stop" ) { print "$0: ERROR: pid $proc->{pid} still stopped!\n"; print " state: $newstate\n"; exit -1; } } print "pid $proc->{pid} is runabble.\n"; exit 0; }