• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1887
  • Last Modified:

count number of running process

i only learning unix, but have a very basic perl background.

i want to write a perl program that will count the number of processes the user is running?

in my perl file i have

$counter = "ps/wc -w";

but this dont work!

any help?

basically i want to pass the num of process to the $counter variable using a pipe...

Ellandrd
0
ellandrd
Asked:
ellandrd
1 Solution
 
koppchaCommented:
print `ps/wc -w`


use backticks
0
 
koppchaCommented:
use backticks but the unix command is wrong
0
 
koppchaCommented:
use this unix command
ps -u <userid> | grep -v pid | wc -l
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TintinCommented:

$counter = `ps | grep -cv PID` or die "Can not run ps $!\n";

0
 
ellandrdAuthor Commented:
ive using this but its returning 2:

$myProcessesCounter = `ps -ef | grep =~/3404/g | wc -l`;

but if i try this:

use Proc::ProcessTable;
$t = new Proc::ProcessTable;
foreach $p (@{$t->table})      
            {
                  if ($p->uid =~ /3404/g)
                  {
                        $myProcessesCounter++;
                  }
            }

it returns 20, but when i print a  report of my process, it show only 19... somewhere its adding an extra 1...

am confused, i just need to count number of process running where uid = 3404

0
 
koppchaCommented:
$myProcessesCounter = `ps -fu3404 | grep -cv PID`;

ps -e will list all the processes which you donot want.You want the processes specific to the user so use -u option
0
 
Nisus091197Commented:
Hi,

a slight modification, replace UID with username:

 $myProcessesCounter = `ps -fu oracle | grep -c oracle`;

Regard, Nisus
http://www.omnimodo.com
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now