next up previous
Next: The autoexec.sas file Up: Utilities Previous: Looking at SAS datasets:

Killing all sas processes: saskill

I often want to stop a SAS process midway. The proper way to do this is to list my processes:

    ps -fu `whoami`
to find the process ID (PID) of the SAS process and kill it by typing
   kill -9 <PID>

On some Unix systems this can be done in one step my using the killall command, which takes as its argument the commandname which you want to kill all instances of:

   killall sas

This command is not available on all systems. However, there's nothing easier than automating the two-step process above:

#!/usr/bin/perl -w

my @userpids = `ps -u $ENV{'USER'} -o pid=`; #Get a list of PIDs I (that is, $ENV{'USER'}) am running

my @saspids=`ps -C sas -o pid=`; #Get a list of PIDs corresponding to SAS processes

chomp(@userpids); #Remove trailing newlines
chomp(@saspids); #Remove trailing newlines

my %original = ();
my @isect = ();

map { $original{$_} = 1 } @userpids;
@isect = grep { $original{$_} } @saspids; #Find the intersection of the two lists

foreach my $pid (@isect) #Kill each process whose PID is in the intersection
{
    print "Killing pid: $pid\n";
    my $a=`kill -9 $pid`;
}

I save this as a file named saskill in a folder in my path, make it executable, and call it by saying

  saskill

at the prompt.



Andre de Souza 2012-11-19