Appropriate Tools and Approach for Kill Application

Appropriate Tools and Approach for Kill Application

Post by m.. » Thu, 18 Apr 1996 04:00:00



I am interested in writing a fancy program to kill processes and could use
some advice on appropriate tools, languages, and approaches.

I would like the program to function as follows:

There will exist a command line switch to correspond to each process
characterstic. A process characteristic will most likely be each of the
fields displayed in a full process list (ps -ef on many systems.) Using
these switches, a user will be able to specify one or more characteristics
with the ability to use regular expressions.  Also, where appropriate, he
or she may include processes to be killed by using equalities/
inequalities.

i.e.

kill -n x*

would kill xterm, xrn, xmosaic, etc.

kill -n x* -t >=5h2m

would kill all processes beginning with lowercase x and which have been
running at least than five hours and two minutes.

These examples are provided to give a basic idea--I haven't worked out the
syntax yet.

Lastly, I would like the user to be able to specify criteria for EXCLUDING
processes based on values for these same characteristics.

Can you please help with the following questions:

1) What tools or languages would be best to use?  C, Tcl, scripting langs,
LEX & YACC, etc.

2) What are some good strategies and their pros and cons for implementing
this functionality in different software forms i.e. script, program,
combination, etc.

3) Are there any guidelines or tips for designing the syntax to jive with
standard practice?

Thanks so much for your help.

Michael Weiss

 
 
 

Appropriate Tools and Approach for Kill Application

Post by Michael Luebbe » Thu, 18 Apr 1996 04:00:00



>i.e.
>kill -n x*
>would kill xterm, xrn, xmosaic, etc.

Got smthng, quick&dirty programmed, but maybe a start for you:

Its from my early programming days, so dont wonder bout
root hacking without the use of popular modules like getopt.....
its always spitting out, that processes weren`t killed,
but they are, just ognore it.

If anyone is interested, I will do some effort to nicen this stuff up.
email me......

-----------------------8<------------------------------>8-----------------------------------------------------
#!/usr/bin/perl
# perl script to kill a spcific program
#

$query = 0;
$mode = -1;
$verbose = 0;
$pattern = "";


{
 if ($ARGV[$in] =~ /[-\/]v/)
 {
  $verbose = 1;
 }
 if ($ARGV[$in] =~ /[-\/]q/)
 {
  $query= 1;
 }
 if ($ARGV[$in] =~ /[-\/]ma/)
 {
  $mode = 0;
 }
 if ($ARGV[$in] =~ /[-\/]mr/)
 {
  $mode = 1;
 }
 if ($ARGV[$in] =~ /[-\/]mt/)
 {
  $mode = 15;
 }
 if ($ARGV[$in] =~ /[-\/]mk/)
 {
  $mode = 9;
 }
 if ($ARGV[$in] =~ /[-\/][Pp]/)
 {
  $pattern = $ARGV[$in+1];
  if ($verbose == 1)
  {
   print "Looking for pattern: <$pattern>\n";
  }
 }

Quote:}


{
 print "KILL: killing processes\nusage: kill [-q] [-v] -m[r|t|k|a] -p
pattern\n";
 print "\t\t-m : r=restart(SIGHUP) t=terminate(SIGTERM)
k=kill(SIGKILL) a = try all\n";
 print "\t\t-q=query\n\t\t-v=verbose\n ";
 exit;

Quote:}

open(PS, "ps -ax |");

while (<PS>)
{
 chop($_);
 $_ =~ s/^\s*//;
 $_ =~ s/\s*$//;
 $_ =~ s/ +/,/o;
 $_ =~ s/ +/,/o;
 $_ =~ s/ +/,/o;
 $_ =~ s/ +/,/o;

 &kill_pattern($pattern, $pid, $name, $time, $tty);

Quote:}

sub kill_pattern
{

 if ($$ eq $pid)
 {
  return;
 }

 if ($name =~ /$pattern/)
 {
  if (($query ==1) || ($verbose == 1))
  {
   print "Kill <$name> PID <$pid> Time <$time> TTY <$tty> ";
  }
  if ($query == 1)
  {
   print " Should I kill it? ";
   if (<STDIN> =~ /[NnQq]/)
   {
    return;
   }
  }

  if ($mode == 0)
  {
   print "Sending HUP ...";
   if ((kill(1 , $pid) == 0) || (&test_kill($pid) == 0))
   {
    print "Sending TERM ...";
    if ((kill(15 , $pid) == 0) || (&test_kill($pid) == 0))
    {
     print "Sending KILL ...";
     if ((kill(9 , $pid) == 0) || (&test_kill($pid) == 0))
     {
      print " can't kill it.\n";
      return;
     }
    }
    print " ... OK.\n";
   }
  }
  else
  {
   print "Sending Signal <$mode> ...";
   if ((kill($mode, $pid) == 0) || (&test_kill($pid) == 0))
   {
    print " ... no success.\n";
    return;
   }
   print " ... OK.\n";
  }
 }
 return;

Quote:}

sub test_kill
{
 $p = $_[0];
 open(TEST, "ps -p $p |");

 close(TEST);


 {
  if ($i =~ /^\s*$p/)
  {
   return 0;
  }
 }
 return 1;

Quote:}


 
 
 

Appropriate Tools and Approach for Kill Application

Post by Kazimir Kylhe » Thu, 18 Apr 1996 04:00:00



 >I am interested in writing a fancy program to kill processes and could use
 >some advice on appropriate tools, languages, and approaches.
 >
 >I would like the program to function as follows:
 >
 >There will exist a command line switch to correspond to each process
 >characterstic. A process characteristic will most likely be each of the
 >fields displayed in a full process list (ps -ef on many systems.) Using
 >these switches, a user will be able to specify one or more characteristics
 >with the ability to use regular expressions.  Also, where appropriate, he
 >or she may include processes to be killed by using equalities/
 >inequalities.
 >
 >
 >i.e.
 >
 >kill -n x*
 >
 >would kill xterm, xrn, xmosaic, etc.
 >
 >
 >kill -n x* -t >=5h2m
 >
 >would kill all processes beginning with lowercase x and which have been
 >running at least than five hours and two minutes.

Basically, the ``killall'' command that distributes with Slackware linux has
some functionality along this vein. If you type ``kilall xterm'', it will kill
all xterms.

 >Can you please help with the following questions:
 >
 >1) What tools or languages would be best to use?  C, Tcl, scripting langs,
 >LEX & YACC, etc.

I'd write an awk script which processes the output of ps, but I'd try to patch
it together using POSIX.2 shell scripting first, in conjunction with grep and
friends. As a last resort, I'd resort to things that are not POSIX.2
standardized, like perl, etc.

 >2) What are some good strategies and their pros and cons for implementing
 >this functionality in different software forms i.e. script, program,
 >combination, etc.

A script is likely to be easier to port than a C program.

 >3) Are there any guidelines or tips for designing the syntax to jive with
 >standard practice?

Hell no! Does comp.macintosh.programmer appear in any of the newsgroups you
spammed? :)

Don't even DARE to be consistent with any other command, you blasphemer! :))

Seriously, the ``find'' syntax might be cool.

        findjob -name "x*" -user bob -exec kill -STOP {} \;

Find is the most user-friendly program there ever was, so that's the one to
emulate.
--
I'm not really a jerk, but I play one on Usenet.

 
 
 

1. Appropriate Tools and Approach For Kill Application

I am interested in writing a fancy program to kill processes and could use
some advice on appropriate tools, languages, and approaches.

I would like the program to function as follows:

There will exist a command line switch to correspond to each process
characterstic. A process characteristic will most likely be each of the
fields displayed in a full process list (ps -ef on many systems.) Using
these switches, a user will be able to specify one or more characteristics
with the ability to use regular expressions.  Also, where appropriate, he
or she may include processes to be killed by using equalities/
inequalities.

i.e.

kill -n x*

would kill xterm, xrn, xmosaic, etc.

kill -n x* -t >=5h2m

would kill all processes beginning with lowercase x and which have been
running at least than five hours and two minutes.

These examples are provided to give a basic idea--I haven't worked out the
syntax yet.

Lastly, I would like the user to be able to specify criteria for EXCLUDING
processes based on values for these same characteristics.

Can you please help with the following questions:

1) What tools or languages would be best to use?  C, Tcl, scripting langs,
LEX & YACC, etc.

2) What are some good strategies and their pros and cons for implementing
this functionality in different software forms i.e. script, program,
combination, etc.

3) Are there any guidelines or tips for designing the syntax to jive with
standard practice?

Thanks so much for your help.

Michael Weiss

2. Internet Connectivity/Cable modem-Solaris 9

3. kill xterm == kill application

4. What exactly does "supports Linux" mean?

5. TCP-IP application : a multithreaded approach

6. Cable modem, ethernet, and DHCP

7. TCP-IP Application : Multithreaded approach

8. Threads for Linux?

9. Appropriate Tools for "enhancing" / "fixing" / creating Linux GPLed code

10. Matrox Mystique ands X.

11. KILL KILL KILL

12. Kill COREL; Kill COREL; Kill COREL; ...

13. A method to kill process that cannot be killed even with `kill -9'.