Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3606344
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:14:12+00:00 2026-05-18T21:14:12+00:00

On Linux, is it possible to somehow disable signaling for programs externally … that

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:14:12+00:00Added an answer on May 18, 2026 at 9:14 pm

    The process signal mask is inherited across exec, so you can simply write a small wrapper program that blocks SIGINT and executes the target:

    #include <signal.h>
    #include <unistd.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
            sigset_t sigs;
    
            sigemptyset(&sigs);
            sigaddset(&sigs, SIGINT);
            sigprocmask(SIG_BLOCK, &sigs, 0);
    
            if (argc > 1) {
                    execvp(argv[1], argv + 1);
                    perror("execv");
            } else {
                    fprintf(stderr, "Usage: %s <command> [args...]\n", argv[0]);
            }
            return 1;
    }
    

    If you compile this program to noint, you would just execute ./noint ./y.

    As ephemient notes in comments, the signal disposition is also inherited, so you can have the wrapper ignore the signal instead of blocking it:

    #include <signal.h>
    #include <unistd.h>
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
            struct sigaction sa = { 0 };
    
            sa.sa_handler = SIG_IGN;
            sigaction(SIGINT, &sa, 0);
    
            if (argc > 1) {
                    execvp(argv[1], argv + 1);
                    perror("execv");
            } else {
                    fprintf(stderr, "Usage: %s <command> [args...]\n", argv[0]);
            }
            return 1;
    }
    

    (and of course for a belt-and-braces approach, you could do both).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Linux redhat 3, can someone explain how is that possible that i
I want to install eclipse in linux, Is it possible to install eclipse without
So (I havent tried yet) but it somehow seems that video for linux 2
On linux, it's possible to create a tun interface using a tun driver which
In Linux, what is the difference between /dev/ttyS0 and /dev/ttys0 ? I know that
I have an x86-64 computer running Linux that I would like to supplement with
just a quickie (or maybe not:] ): Is it possible to get somehow list
I'd like to know if it's possible to find out the command that a
Is it possible to set environment variable with maven (OS: Linux)? I already have
Is it possible to use gvim to edit remote Linux files if I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.