3

I have a bash script, which start 2 processes:

openocd ...flags... 2>openocd.log &
arm-none-eabi-gdb

When in gdb, interrupting execution with Ctrl+C causes openocd to receive SIGINT as well and, thus it stops. I've tried to trap and reissue SIGINT directly to gdb with:

trap 'kill 2 $!' INT

But apart from requiring root, it does not work anyway:

./dbg.sh: 1: kill: No such process

Are there elegant ways to perform the task?

__

Well, running script with debug options on helped a lot. But still I encounter weird behavior. Here is the content of my script:

#!/bin/sh
set -vx
trap 'killall -s2 arm-none-eabi-gdb-py' 2
openocd -f ...flags... 2>openocd.log & arm-none-eabi-gdb-py

When I run killall -s2 arm-none-eabi-gdb-py from within different tty - it terminates execution of remote target and does not close openocd, but sending SIGINT through Ctrl+C returns:

+ killall -s2 arm-none-eabi-gdb-py
arm-none-eabi-gdb-py: no process found

Seems like trap does not inhibit signals at all... changing to trap 'ps -ef' INT reveals, openocd AND gdb are already down when the trap command executes.

Peter V
  • 71
  • 4
  • try making it all one script (with the `trap` included), and adding `set -vx` before the `trap` to see what is getting set when. I'm not sure that `set -vx` will emit the `trap` trace, but it's worth trying. Good luck. – shellter Mar 18 '18 at 02:54
  • `kill 2 $!` should be `kill -2 $!`. – John Kugelman Oct 19 '18 at 17:07

1 Answers1

-1

Isn't there a missing '&' in your instruction (it would give that)?

openocd -f ...flags... 2>openocd.log &**&** arm-none-eabi-gdb-py
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Bsquare ℬℬ
  • 4,423
  • 11
  • 24
  • 44
  • No, `&` is correct. `&` causes `openocd` to run in the background (as opposed to `;` which runs it in the foreground). – John Kugelman Oct 19 '18 at 17:06
  • So why there is a arm-none-eabi-gdb-py command just after on the same line? I mean, it looks strange and could be different from what intended the author of the question. – Bsquare ℬℬ Oct 19 '18 at 19:40
  • That's how you run two commands simultaneously. There doesn't need to be a newline after the `&`, it's optional. – John Kugelman Oct 19 '18 at 20:06