[Techtalk] how to get PID without using pidof command?

Michelle Murrain tech at murrain.net
Fri Sep 19 16:16:21 EST 2003


On Fri, 2003-09-19 at 15:09, ruchika khera wrote:
>    Hi,
> 
>    Just when I figured out how to use pidof and kill commands to signal a
>    process, I learnt that the embedded platform I am using does not
>    support pidof and find commands. It does support other popular
>    commands such as ps, grep, kill, ls.
> 
>    I have a shell script that gets a process's PID and sends it a signal.
>    kill -s testsig# $(pidof test)
> 
>    Can someone help me do this without using pidof?

I'm horrible at shell scripting, but what I'd do in perl is:

#!/usr/bin/perl
use strict;

my $process = `ps aux | grep test`;  ## where 'test' is the name of the
process;
(my $owner, my $pid, my $junk) = split(' ',$process); # get the pid from
that process listing
my $killed = system ("kill -s HUP $pid"); #kill the process


You might want to parse the exit status of the kill command, which will
be in $killed.

I'm sure that a shell scripter (as well as a better perl coder) could
come up with a much more elegant solution...

HTH
-- 
.Michelle
---------------------------
Michelle Murrain
tech at murrain.net
http://www.murrain.net
ph:413-253-2874
cell:413-222-6350
AIM:pearlbear0 Y!:pearlbear9 ICQ:129250575

"Windows is not ready for the Internet" - comment on security blog



More information about the Techtalk mailing list