1

I am trying to catch signals in c and ignore them for the parent process while the child handles them normally. I currently have:

   #include<signal.h>
   #include<bits/sigaction.h>

   int main(){
     struct sigaction parentsig, childsig;
     parentsig.sa_handler = SIG_IGN;
     sigaction(SIGINT, &parentsig, &childsig);
     return 0;
   }

I am currently compiling it with gcc -std=c99 -o smallsh smallsh.c, but I get the error implicit declaration of function ‘sigaction’. After some debugging I found out that it has to do with sigaction(SIGINT, &parentsig, &childsig) line. Every example that I can find has something similar to this since it sets what struct to follow when handling signals. Can someone explain what I'm doing wrong with this?

Nick
  • 11
  • 4
  • 1
    Please show an [Minimal Complete and Verifiable Example](https://stackoverflow.com/help/mcve). Sounds like you have just left out `#include ` but can't say for sure without an MCVE. – kaylum Nov 23 '15 at 04:32
  • Sorry, I have included and . It does not through any errors or warning if I eliminate `sigation(SIGNINT, &parentsig, &childsig);` – Nick Nov 23 '15 at 04:47
  • Please show an MCVE. There is no way we can tell you what the problem is with the information provided. – kaylum Nov 23 '15 at 04:51
  • Remove `#include`. – kaylum Nov 23 '15 at 04:55
  • When I remove `#include`, I get `storage size of ‘parentsig’ isn’t known` and `storage size of ‘childsig’ isn’t known` errors along with the one I was getting before. – Nick Nov 23 '15 at 04:59
  • Sorry I missed the `c99` part of your compile line. My understanding is that `sigaction` does not conform to c99. You need to take that out or use `signal` instead. – kaylum Nov 23 '15 at 05:06
  • Thanks, that seems to have fixed it. – Nick Nov 23 '15 at 05:20
  • @kaylum: `sigaction()` is POSIX. The c-standard version is irrelevant. – EOF Nov 23 '15 at 15:10

0 Answers0