Skip to content

Instantly share code, notes, and snippets.

@kuremu
Created November 23, 2019 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuremu/1b51ee6d4ec23af654c76378e6dacc89 to your computer and use it in GitHub Desktop.
Save kuremu/1b51ee6d4ec23af654c76378e6dacc89 to your computer and use it in GitHub Desktop.
Wrapper program to block SIGINT for spawned process
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
# https://stackoverflow.com/a/4515549
# compile with `gcc -g -o noint noint.c`
# usage `./noint <command> [args...]`
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment