Hi,
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=$MY
On Thu, Apr 11, 2013 at 01:05:43PM +, Lenga, Yair wrote:
> Is it possible to add back the functionality to allow the child process to
> somehow retrieve it's OWN PID.
You are looking for the BASHPID variable, which expands to the process
ID of the current bash process (even in a subshell).
On Thursday, April 11, 2013 01:05:43 PM Lenga, Yair wrote:
> 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 th
On 4/11/13 9:24 AM, Dan Douglas wrote:
> On Thursday, April 11, 2013 01:05:43 PM Lenga, Yair wrote:
>> 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
>
Dan, Chet: Many thanks for the info about BASHPID.
I've checked BASHPID on RH6, and it looks OK. Few comments related to making
the change visible, and POSIX compliance.
+ The 'set' command, does not print the BASHPID, this make it very hard to find
it (unless you read every line in the BASH i
On Thu, Apr 11, 2013 at 04:15:45PM +, Lenga, Yair wrote:
> + The man page list BASH_VERSION, etc., but no indication of BASHPID. It's
> probably a good idea to put a note next to '$!' about BASHPID.
It is certainly in the man page:
BASHPID
Expands to the process ID of the c
On Thursday, April 11, 2013 04:15:45 PM Lenga, Yair wrote:
> ( echo "$!") &
> ( echo "$!") &
>
> According to POSIX, both calls should print "" (nothing). As the background
> command does not come from the "current" shell.
>
> With BASH4, The first call will print "" (nothing), second call will p
On 4/11/13 12:15 PM, Lenga, Yair wrote:
> Dan, Chet: Many thanks for the info about BASHPID.
>
> I've checked BASHPID on RH6, and it looks OK. Few comments related to making
> the change visible, and POSIX compliance.
>
> + The 'set' command, does not print the BASHPID, this make it very hard t
Hi. I made an important update on the functions. I should have include -d
'' to read. Not sure why I didn't notice it during the test back then. The
previous versions would only read a single id but that's fixed now. Good
thing I remembered the code after stumbling upon another problem.
I thought