The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-20-2008
mirusnet's Avatar
mirusnet mirusnet is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 146
Pid

How can I put the process id of ,for example, the following script to the pid file? Maybe $$ must be defined in some place?
Code:
daemon(){
        while true;
        do
                if [ -r "${FILE}" ]
                then
                        echo "`date +"%H:%M:%S"`" >> $FILE
                        sleep 3;
                fi
        done
}
daemon >/dev/null 2>&1 &
  #2 (permalink)  
Old 02-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,759
FYI: $$ is the pid of the current process, so:
Code:
echo "`date +"%H:%M:%S"` $$" >> $FILE
does write the pid to $FILE, but it is a child process because the & runs the function in the background.
  #3 (permalink)  
Old 02-20-2008
Lukeadams Lukeadams is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
Good point... You may be able to 'source' the command by prepending a period[SPACE] so it runs in the same process/shell.

Untested but worth a shot:

Code:
. echo "`date +"%H:%M:%S"` $$" >> $FILE
  #4 (permalink)  
Old 02-20-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,759
I think the "daemon" is meant to run by itself in a child process. It doesn't do much.
Maybe they use to track usage of the script that runs it...
  #5 (permalink)  
Old 02-20-2008
mirusnet's Avatar
mirusnet mirusnet is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 146
This example script works perfect only in following configuration:
Code:
daemon(){
        echo $$ > ${PF}
        while true; 
        do 
                if [ -r "${FILE}" ]
                then 
                        echo "`date +"%H:%M:%S"`" >> $FILE
                        sleep 3;
                fi
        done
}

#MAIN
case $1 in
        -daemon)
                daemon
                ;;
        *)
                $0 -daemon &
                ;;
esac
exit 0
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0