Solved

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

Posted on 2008-10-24
2
4,930 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 500 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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

739 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