if pid exist ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if pid exist ?
# 1  
Old 08-16-2010
if pid exist ?

Hi I need help to whit a script that start a program if a nother program is started first .
I thought something like this .

Code:
if [ "ps aux | grep program1" is bigger than 0 ] then start program 2

Thanks
# 2  
Old 08-17-2010
Code:
c=$(ps aux | grep program1|wc -l)

if [[ "$c" -eq 1 ]]
then
  start program 2
fi

# 3  
Old 08-17-2010
the above code will have $c as always one, as grep would be in the list of ps.

so it should be
Code:
c=`ps aux|grep program1|grep -v grep|wc -l`

Please correct me if i am wrong
# 4  
Old 08-17-2010
That's the reason I don't use "-eq 0"

if using your code, I have to change the if command to :

Code:
if [[ "$c" -eq 0 ]]

# 5  
Old 08-17-2010
sorry rdcwayx.

I was misled.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Why does a fakechroot exist?

I am really confused as to why a tool like fakechroot exists and what does it do. Chroot is an ability only for root users, correct? Then a tool that allows to bypass that is clearly a security flaw, correct? When and why would you need something like this? Is there any relation between... (7 Replies)
Discussion started by: sreyan32
7 Replies

2. Homework & Coursework Questions

Group Doesn't Exist

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I'm able to create a group but when I'm trying to delete the group it keeps stating Group Doesn't Exist. I know... (2 Replies)
Discussion started by: GoBoyGo
2 Replies

3. UNIX for Dummies Questions & Answers

Does ${%name} exist in csh?

I have this code in tcsh and would like to know whether the syntax below will work in csh. if( "${%rsl}" == 0 ) then echo "rsl is empty" endif ---------- Post updated at 06:38 AM ---------- Previous update was at 05:53 AM ---------- It does not seem so. Perhaps the best thing is to... (2 Replies)
Discussion started by: kristinu
2 Replies

4. Shell Programming and Scripting

To see if a program exist and is executable

Hi, I am making a program that needs to detect if the program name in parameter is a valid runable program. But the line if ; then never seem to work. Even if I run like: ./script cat "-u" cat "-u" inputfile Thank you everyone. #!/bin/bash # usage() { #print usage message and quit... (4 Replies)
Discussion started by: leonmerc
4 Replies

5. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

6. UNIX for Dummies Questions & Answers

su: user x does not exist

somehow my user names and groups on one of our machines are changed to numbers 700, 701, etc. thus, i can only ssh into this machine as root. is there a way to migrate the user names and groups to this machine? thanks! (3 Replies)
Discussion started by: user23
3 Replies

7. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

8. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

9. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

10. UNIX for Dummies Questions & Answers

does it exist in linux?

Is there a jumpstart equivalent tool in the linux environment? (1 Reply)
Discussion started by: pbonilla
1 Replies
Login or Register to Ask a Question