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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$pid = `ps -ef -o pid,ppid,comm | grep xview | awk '{print \$1'}`;
#or
$pid = join"\n",map{(split)[0]}gr ep/xview/, `ps -ef -o pid,ppid,comm`;
$pid = join"\n",map{(split)[0]}gr