More ps questions.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting More ps questions.
# 1  
Old 11-18-2010
More ps questions.

Hey all,

Thanks for all the help you have given me. Two more things I am trying to figure out.

I need to issue a command..example


Code:
ps -ef | grep <process>

This would return about 10-15 running processes. I need to verify that there are x amount of processes running. What is the best way to do that.

Next, I need to verify that the one process that is running is in a certain status aka connected..so when the grep is ran, I need it to verify that the PID is in a certain status.

Thanks for all the help so far guys
# 2  
Old 11-18-2010
Code:
n=$(ps -ef | grep <process> | wc -l)
echo "$n <process> are currently running"

# 3  
Old 11-18-2010
Some version of grep support -c, --count only print a count of matching lines per FILE option, please read your grep manual OR pgrep.
# 4  
Old 11-19-2010
Thank you all, The second part of the question was how do I make it so that it looks for this..

Code:
 
    root  233222  912332   0   Nov 16      -  0:08 process-database: db (idle) 
    root  614574  912332   0   Nov 16      -  0:09 process-database: db (idle) 
    root  912332       1   0   Nov 16      -  0:00 process-database: (accepting) 
 user     991264 1343556   0 08:59:12  pts/0  0:00 grep process 
    root 1032222  912332   0   Nov 16      -  0:09 process-database: db (idle) 
    root 1310832  912332   0   Nov 16      -  0:11 process-database: db (idle) 
    root 1231333  912332   0   Nov 16      -  0:00 process-database: license (Cur(0), Max(100))

I need to make sure that the one PID says "(accepting)"

first step I would assume would be

Code:
ps -ef | grep process > process.out

Then I just need to look for the literal string "accepting"...

Last edited by jeffs42885; 11-19-2010 at 10:33 AM..
# 5  
Old 11-19-2010
Code:
ps -ef | grep accepting

This User Gave Thanks to ctsgnb For This Post:
# 6  
Old 11-19-2010
Quote:
Originally Posted by ctsgnb
Code:
n=$(ps -ef | grep <process> | wc -l)
echo "$n <process> are currently running"

The grep process itself needs to be excluded. If the process is called "gnorky", you can use:
Code:
ps -ef | grep [g]norky

for example
This User Gave Thanks to Scrutinizer For This Post:
# 7  
Old 11-19-2010
Thank you again.

I am almost there

Can you tell me what is wrong with the code? I am getting the grep process back.

Here's what I have

Code:
n=$(ps -ef | grep process | grep -v process | wc -l) 
echo "$n process are currently running"

There should always only be 1 process running and it's coming back zero.

EDIT -

Thank you very much scrutinizer, that works perfectly!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Vi questions

Hello, I would like to know how we can highlight/select a section of a file in vi and delete that section if we don't want to use the dd command to delete one line at at time. There is one where we don't want to delete the whole line , but up to a certain word. (2 Replies)
Discussion started by: Pouchie1
2 Replies

2. UNIX for Dummies Questions & Answers

Just had a few questions

1) The lpr and sort utilities accept input either from a file named on the command line or from standard input. a)Name two other utilities that function in a similar manner. b)Name a utility that accepts its input only from standard input. 2) Explain the following error message. What... (10 Replies)
Discussion started by: youngyou
10 Replies

3. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

4. Programming

two questions

hey all, I have question when am writing simple shell... in the child am calling execvp, i want the parent to know when execvp returns - 1. how can i let the parent know the result of execvp thanks in advance (9 Replies)
Discussion started by: joey
9 Replies

5. UNIX for Dummies Questions & Answers

Just a few questions.

Hi everyone im new to this forums, i just wanted to get started by asking a few question(Im a Unix newbie) 1. How do i sort a file called "dirr" in a ascending order on the 3rd column 2. what does alias on=who do Thanks in advance!!! (1 Reply)
Discussion started by: Da Paper
1 Replies

6. Solaris

2 Questions

Hello Everbody I hope you can give me a hand, I have some questions The first one itīs about some message that I donīt know what means, I was looking about it. but nothing. This is the message rsh: connection from bad port bsd-gw: Error reading from connection: Bad file number And my... (4 Replies)
Discussion started by: lo-lp-kl
4 Replies

7. Programming

C questions

What does "extern" do? ex. extern int x; and another question, what about using static in functions? like: static void foo(), why? (2 Replies)
Discussion started by: Esaia
2 Replies

8. UNIX for Dummies Questions & Answers

i got some questions :)

Hi! Im new to all this but the computer club im in has unix i think. now my questions. 1.is it NTFS i need to partion the harddrive with to be able to use unix? 2.Unix and Linux whats the diffrense?yes im a noob got no idea been using crap windows for ages and hate it. 3.I got a win98... (2 Replies)
Discussion started by: Pierre
2 Replies
Login or Register to Ask a Question