Sponsored Content
Top Forums Shell Programming and Scripting [SOLVED] Using "$!" to get the PID of the Last Ran Background Process Post 302703341 by mrm5102 on Wednesday 19th of September 2012 03:50:36 PM
Old 09-19-2012
[SOLVED] Using "$!" to get the PID of the Last Ran Background Process

Hello All,

I was looking into creating a script that would be used only to start a Daemon and create a lock file...
F.Y.I. It's for Nagios' NRPE Daemon Plugin...

Anyway when I run the command to start the Daemon (below):
Code:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

And try to get the PID of that Command just ran by adding this to the end of that line above:
Code:
...-c nrpe.cfg & echo $!

The PID it prints out is NOT the PID of the NRPE Daemon. Am I not using the "echo $!" correctly...?

On one of the boxes im trying this on, which is SLES 11.1 (Bash), the PID it prints out is one number
less then what the actual PID of the Daemon is.

For Example:
Code:
 # /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d & echo $!
[1] 27329
27329



# ps -ef | grep [/]usr/local/nagios/bin/nrpe
nagios   27330     1  0 15:20 ?        00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

I thought maybe it was just a coincidence, so I tried it a few more times, and still it does the same thing.
So I figured I would just implement this one and just subtract 1 from the PID it gives me to
get the real PID, but I then tried this same thing on an AIX server and the actual PID was completely random. So
I decided not to do that (probably wouldn't have been a good idea anyway)...


Does anyone know what I'm doing wrong, or if there is a better way to get this PID (without doing the 'ps -ef | grep ...')..??

Any thoughts would be great!


Thanks in Advance,
Matt
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Process seen in "ps aux" but not "top"

Hi, I have a process that can be seen after "ps aux" command. However when I do "top" command. This process cannot be seen. How can this happen? Is there anything wrong with my code? (3 Replies)
Discussion started by: monkfan
3 Replies

2. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

3. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

4. Red Hat

"service" , "process" and " daemon" ?

Friends , Anybody plz tell me what is the basic difference between "service" , "process" and " daemon" ? Waiting for kind reply .. .. (1 Reply)
Discussion started by: shipon_97
1 Replies

5. UNIX for Advanced & Expert Users

Why the nohup-ed background process always is "stopped" ?

I let a script A call script B. I used nohup a.sh &>/tmp/log & In script A it calls B directly, without any redirecting or nohup or background. However A is always "Stopped", while B is running correctly. Anybody knows why? thanks! -----Post Update----- BTW, if I don't use nohup... (1 Reply)
Discussion started by: meili100
1 Replies

6. Shell Programming and Scripting

Why the nohup-ed background process always is "stopped" ?

I let a script A call script B. I used nohup a.sh &>/tmp/log & In script A it calls B directly, without any redirecting or nohup or background. However A is always "Stopped", while B is running correctly. Anybody knows why? thanks! -----Post Update----- BTW, if I don't use nohup... (4 Replies)
Discussion started by: meili100
4 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
kcfd(1M)						  System Administration Commands						  kcfd(1M)

NAME
kcfd - kernel-level cryptographic framework daemon SYNOPSIS
kcfd DESCRIPTION
The kcfd daemon helps in managing CPU usage by cryptographic operations performed in software by kernel threads. The system utilization associated with these threads is charged to the kcfd process. It also does module verification for kernel cryptographic modules. Only a privileged user can run this daemon. The kcfd daemon is automatically invoked in run level 1, after /usr is mounted. A previously invoked kcfd daemon that is still running must be stopped before invoking another kcfd command. Manually starting and restarting kcfd is not recommended. If it is necessary to do so, use the cryptoadm(1M) start and stop subcommands. EXIT STATUS
The following exit values are returned: 0 Daemon started successfully. > 1 Daemon failed to start. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsl/SUNWcslx | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
cryptoadm(1M), attributes(5) SunOS 5.10 30 Sep 2003 kcfd(1M)
All times are GMT -4. The time now is 12:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy