help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] get pid of exited process


From: Stas Sergeev
Subject: Re: [Help-bash] get pid of exited process
Date: Sun, 3 Jan 2016 20:44:24 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

03.01.2016 20:10, Stas Sergeev пишет:
If even with that in mind you want to proceed, you can do this:
Thanks! That's a nice trick that works well for me.

The reason I need this, is for the program-specific cleanup.
Programs usually create the pipes and sockets, embedding
the PID in their names. If such program crashes, the startup
script needs to do the cleanup. For that it needs to know the
pid of the program it was executing.
I think such scenario is valid and rather common, so I am a
bit upset bash does not have a native support for this.
But your trick is almost as convenient as the native support.
Ah, except for the nasty side-effect!
What I do, is:

P=$(echo $BASHPID; exec my_app)

But the problem is that the stdout of my_app also goes into P.
Example:
$ P=$(echo $BASHPID; exec /bin/echo test)
$ echo $P
7535 test

This is not what I need. I need my_app to still use its tty.
The work-around I can think of, is:

exec 3>&1
P=$(echo $BASHPID; exec 1<&3; exec $COMMAND)
exec 3>&-

but is there a simpler fix?
I guess there is some syntax to use another FD to pass
the subshell's output to the parent - what would it be? :)



reply via email to

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