help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Use pid of cmd run in sub shell in parent shell?


From: Greg Wooledge
Subject: Re: [Help-bash] Use pid of cmd run in sub shell in parent shell?
Date: Thu, 1 May 2014 15:54:45 -0400
User-agent: Mutt/1.4.2.3i

On Thu, May 01, 2014 at 07:46:29PM +0000, Patrick Schleizer wrote:
> while read line; do
>    log "...: $line"
> done < <(
>    {
>       long_running_cmd_here
>    }
> ) &
> 
> echo "Need pid of long_running_cmd_here here."
> 
> =====
> 
> I need the pid of long_running_cmd_here for job control, so I can send
> signals to long_running_cmd_here.

When you need finer control than <(...) allows, you must set it aside
and use a named pipe.

fifo=${TMPDIR:-/tmp}/myscript.$$
trap 'rm -f "$fifo"' EXIT
mkfifo "$fifo" || exit
{ long_running_cmd; } > "$fifo" & pid=$!
while read line; do ...; done < "$fifo"

<(...) is just a shortcut, and sometimes shortcuts don't let you do what
you need.



reply via email to

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