0

When I start a dd process directly from the Terminal with

dd if=/dev/zero of=/dev/null &

command, and send to it a -SIGINT with

kill -SIGINT <pid>

command, it closes successfully.

But when I start the process from a script

#!/bin/sh
dd if=/dev/zero of=/dev/null &

Then do

kill -SIGINT <pid>

it doesn't affect the process.

I wonder why this is so.
I didn't find any related information on the internet.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • did you use the `$!` variable to reference the pid of the most recently backgrounded process? If not, you need to do so. Good luck. – shellter Oct 28 '19 at 22:22

1 Answers1

1

POSIX says:

If job control is disabled (see the description of set -m) when the shell executes an asynchronous list, the commands in the list shall inherit from the shell a signal action of ignored (SIG_IGN) for the SIGINT and SIGQUIT signals.

This is likely because Ctrl+C sends a sigint to every process in the group, so without this behavior, any backgrounded processes would unexpectedly be killed when you try to interrupt the main script.

that other guy
  • 116,971
  • 11
  • 170
  • 194