[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible bug with BASH V4: The "$!"

From: Lenga, Yair
Subject: Possible bug with BASH V4: The "$!"
Date: Thu, 11 Apr 2013 13:05:43 +0000


I'm using a bash scripts that is running one of the functions in the scripts as 
a "background".

function my_func {
    MAINPID=$$      # Does not work, report PID of main process.
    MYPID=$!           # Work with bash 3.0, return "unbound" value for bash 4.0
    echo "Deamon run as PID=$MYPID MAIN=$MAINPID"

# Main
(my_func) &

With BASH 3.0, the backgrounded task could access the PID of the parent using 
"$$", and the PID
Of itself as "$!".

With BASH 4.0, the script fail, the "$!" is not available to the child process.

Is it possible to add back the functionality to allow the child process to 
somehow retrieve it's OWN PID.
I assume that the behavior of  "$$" cannot be modified at this time.

Is there any other workaround ?

Yair Lenga

reply via email to

[Prev in Thread] Current Thread [Next in Thread]