Record PID when launching

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Record PID when launching
# 1  
Old 11-08-2009
Record PID when launching

I would like to record the PID of a process when i lauch it from my script

something like:

$abc_pid = /apps/abc/abc.bin -port6700

I know I can run the ps command and grep for abc.bin. The idea is that becase the process runs on several ports and the argument list of .bin is quite large, it would be easier if I could capture the PID at run time.

I've tried $abc_pid = $! but this does not work. Also, I've read that sometimes that can give a forked PID instead of the parent.

# 2  
Old 11-09-2009
By using pgrep and the -f option (fur full line matching)
Process="/apps/abc/abc.bin -port6700"
# choose between on of both
PID=$(pgrep -f "$Process") # returns PID where command line matches
PID=$(pgrep -P $$ -f "$Process") # same as above but only whos PPID is the current script
echo "PID = $PID"

# 3  
Old 11-09-2009
thanks, that'll work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

2. Ubuntu

Launchers Not Launching

Some of my .desktop launchers aren't working. When I try to execute it from the main menu nothing happens. When I try to launch it from a terminal I get the following: $ /usr/share/applications/qjoypad.desktop /usr/share/applications/qjoypad.desktop: line 1: Here are the contents of the launcher:... (0 Replies)
Discussion started by: Deluge
0 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Red Hat

Help in launching firefox.

Hi, -- I am new to linux, please bear with my tech terms. I am using Red Hat 4.1.2-48 (Linux version 2.6.18-194.11.1.el5) for the project. This is a remote server and I do not use any GUI. Now I need to install a product that requires me to launch firefox from linux. when i am trying... (3 Replies)
Discussion started by: vj8436
3 Replies

5. AIX

Error launching c++ executable

Hi everybody, I have compiled my code based on the ALPS libraries () and CMake build system with IBM compiler xlC 11.1 on AIX 6.1 at the latest patch level running on an IBM SP Power 6 machine for high-performance computing. When I run the executable I receive this error message: -bash-3.2$... (2 Replies)
Discussion started by: JessicaAlfonsi
2 Replies

6. Shell Programming and Scripting

Launching shell from another

hi, I have shell script ( say that launches another shell script ( say on the server. In shell script, if i call as . <-- it doesnt work, err file not found . ./ <-- it doesnt work, err file not found ./ <-- works why so? BTW the file exists at the... (4 Replies)
Discussion started by: sjc
4 Replies

7. 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

8. Shell Programming and Scripting

Launching Several Shells....

Hi, I need to create a shell that launches several shells named for example svspush (that does nothing but wait) and record their pid in a file. Any inputs please. Thanks, Marconi (1 Reply)
Discussion started by: marconi
1 Replies

9. 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

10. 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
Login or Register to Ask a Question