Link to home
Start Free TrialLog in
Avatar of jewee
jewee

asked on

Help! Writing script to show process id

Hello, I am writing a perl script that will just display the process id given a process name.

Here is a piece of it....

$pid = `ps -ef -o pid,ppid,comm | grep xview | awk '{print $1'}`;
print "pid = $pid\n";

now, when I just run this command via command line-->
ps -ef -o pid,ppid,comm | grep xview | awk '{print $1'}

it prints out only the process id number:
55386

However, when I run it in the script, it prints out:

55386 4593  xview
Am I using the wrong quotes or something?
ASKER CERTIFIED SOLUTION
Avatar of rkosai
rkosai

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ozo
$pid = `ps -ef -o pid,ppid,comm | grep xview | awk '{print \$1'}`;
#or
$pid = join"\n",map{(split)[0]}grep/xview/,`ps -ef -o pid,ppid,comm`;