Externally disabling signals for a Linux program.

Posted by Harry on Stack Overflow See other posts from Stack Overflow or by Harry
Published on 2010-12-23T01:57:59Z Indexed on 2010/12/23 2:54 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

Hello,

On Linux, is it possible to somehow disable signaling for programs externally... that is, without modifying their source code?

Context:

I'm calling a C (and also a Java) program from within a bash script on Linux. I don't want any interruptions for my bash script, and for the other programs that the script launches (as foreground processes).

While I can use a...

trap '' INT

... in my bash script to disable the Ctrl C signal, this works only when the program control happens to be in the bash code. That is, if I press Ctrl C while the C program is running, the C program gets interrupted and it exits! This C program is doing some critical operation because of which I don't want it be interrupted. I don't have access to the source code of this C program, so signal handling inside the C program is out of question.

#!/bin/bash

trap 'echo You pressed Ctrl C' INT 

# A C program to emulate a real-world, long-running program,
# which I don't want to be interrupted, and for which I 
# don't have the source code!
#
# File: y.c
# To build: gcc -o y y.c
#
# #include <stdio.h>
# int main(int argc, char *argv[]) {
#  printf("Performing a critical operation...\n");
#    for(;;); // Do nothing forever.
#  printf("Performing a critical operation... done.\n");
# }

./y

Regards,

/HS

© Stack Overflow or respective owner

Related posts about linux

Related posts about bash