Reputation: 1078
I need a script that runs 'A' and send to it a signal that should terminate it, and I need to iterate that with different signals so what I want basically is
Launch A ->
send signal S to terminate A and check stuff ->
Relaunch A ->
send signal S1 ......
My problem is that in A I've a loop like:
while(1){
scanf()
...DO STUFF...
}
So using a script like
./A arguments
kill -s QUIT A'sPid
won't work, because obviously it will not reach the kill line until A's over, and it won't without a signal or user input.
Can you give me any hint? Thanks, and sorry if it's a banal question, but I've just started learning this stuff.
Upvotes: 0
Views: 210
Reputation: 9381
SIGNAL=yourSignal
while [ condition ] ; do
./a.out &
PID=$!
kill -s $SIGNAL $PID
done
Upvotes: 2
Reputation: 78105
You need to put the A
instance into the background (see this), so that as it runs you can do something else, namely, send it a signal using kill
.
To background a process put an &
at the end, i.e.:
./A arguments &
Once the background process is started the script will move on to the next command.
Upvotes: 2