help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Problems with background jobs


From: David Niklas
Subject: Re: [Help-bash] Problems with background jobs
Date: Wed, 29 Aug 2018 11:39:32 -0400

On Thu, 16 Aug 2018 10:52:32 +0200
"R. Diez" <address@hidden> wrote:
> Hi there:

Hey! Sorry this is so late, but it seems nobody is helping you and I tend
to be the last to respond.
 
> I am trying to implement a solution to this problem:
> 
> https://sourceforge.net/p/openocd/mailman/message/36384989/
> 
> But the exact problem is not relevant. It is about coordinating 
> processes with pipes.
> 
> Ideally, I would do it with a Bash script like this:
> 
> 1) Create an unnamed pipe, like 'coproc' does, but leaving stdin and 
> stdout untouched.

mkfifo foo;

> 2) Start the OpenOCD process as a background job.

openocd --some_option foo &
export OCD="$!";

> 3) Wait for my OpenOCD script to write to the pipe, so that I know that 
> OpenOCD is now ready to accept connections.

head -c1 foo &
 
> If OpenOCD dies during initialisation, reading from the pipe will fail, 
> and the Bash script will exit.

export H="$!";
sleep 15s;
kill $H;
wait $H;

if [ $H -ne 0 ]; then exit; fi

> 4) Start GDB in the foreground, which connects to OpenOCD. The Bash 
> script will continue when GDB exits.

gdb -p $OCD;
 
> 5) Wait for the OpenOCD background job to finish. We do not want to 
> leave zombie processes behind.

wait $OCD;
 
> 6) Exit with OpenOCD's exit code.
<snip>

exit $?;
 


I do not have openocd, nor am I aware of how you intend to tell openocd
to access your pipe in order to pipe data so I have not tested all of the
above code. You might have to use a socket instead if you want
bidirectional communication, but I have no experience there so you will
have to wait for someone else to help you.
Even more confusing to me is that you want to run gdb in the foreground
but you also want to wait for the return of openocd!? Both are not
simultaneously possible. Esp. because gdb will prevent openocd from
exiting, or at least that is what happens when my code fouls up. Then I
run the bt command from within gdb.

Sincerely,
David



reply via email to

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