?
Solved

AIX/Linux -  How to get pid for a running shell script using ps command

Posted on 2008-10-24
2
Medium Priority
?
4,998 Views
Last Modified: 2013-11-17
Hi,

I wrote a shell script to find out the process that is running a same command. In the shell script I use

NPID=`ps uxc | grep -i -w "$CName" | awk '{print $2}' | wc -l`

#NPID will return the number of process that is running the command $CName

PID=`ps uxc | grep -i -w "$CName" | awk '{print $2}'

#PID will return the pid of the process that is running the command $CName

This all goes well. However, if the $CName is not an executable but it is a shell script
then the above line won't work. I guess it is because the shell script is not an executable.

Is there anywhere I can get the NPID and PID for shell script?

In fact, for my purpose. I will have multiple process each running the same shell script. So, I want to know how many process are running the same shell script. An I also want to get (using ps command)  their pid.  All these have to be done in a shell script.

Any idea how to do that.

Thanks!
0
Comment
Question by:xewoox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 22800053
Hi,
use  'ps -ef' instead of 'ps uxc'
wmp
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22800057
Note that you can write NPID as

NPID=`ps uxc | grep -icw "$CName"`

There should be nothing special about whether the command is a binary or a script.  It should still show up in the list (it does on my system)

0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Simple Linear Regression
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question