1

I have a perl script, which indirectly invokes mysql (to execute a long SQL script). I would like to disable Ctrl+C while that script is running, but somehow the signal still reaches mysql, which then says "Ctrl-C -- query killed. Continuing normally." (I believe that's from mysql)

I have:

  • set the $SIG{INT} to 'IGNORE' -- indeed, the Perl script keeps running
  • set a process group on the Perl script -- indeed, ps -e -o uid,pid,ppid,pgid,command shows that mysql is in the same process group as my Perl script
  • mysql is invoked after both of those happened.

Why would that signal still arrive at the mysql process, and how do I prevent that?

1
  • 2
    See unix.stackexchange.com/a/149756/90691; the signal is sent to all processes in the process group. If mysql is in the same process group as the Perl script, the Perl script will ignore it and mysql won't. Jan 24 '20 at 19:58
0

You can ignore signals (SIG_IGN) if you write the code (like in https://stackoverflow.com/questions/3232613/how-to-stop-sigint-being-passed-to-subprocess-in-python) or use trap in shell like in How can we set up a signal trap to be SIG_IGN and SIG_DFL in bash?, i think in perl this is the perlipc library https://metacpan.org/pod/perlipc, IPC is Inter Process Communication

You may also choose to assign the strings 'IGNORE' or 'DEFAULT' as the handler, in which case Perl will try to discard the signal or do the default thing.

source: https://www.mkssoftware.com/docs/man5/perlipc.5.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.