Technical article 100761

What is the correct syntax for the signal(S) and sigaction(S) system calls?

OpenServer 5.0.0

Written · Last revised

Problem

The man pages for the signal(S) and sigaction(S) system calls
show how they are defined but not how to use them.  Consequently
it is difficult to use the correct syntax in a C program.

Solution

These two sample pieces of code show the correct syntax for the signal(S) and sigaction(S) system calls:

#include<stdio.h>
#include<errno.h>
#include<signal.h>
void
myfunc( int sig )
{
      do something ...
}
main( int argc, char *argv[])
{
      if (signal(SIGINT, (void(*)()) myfunc) == SIG_ERR){
              perror("SIGNAL SIGINT: ");
              exit(-1);
      }
}
-----------------------------------------------------------------
#include<stdio.h>
#include<signal.h>
#include<errno.h>

void myfunc( int sig ) { do something when Del key is pressed }

main( int argc, char *argv[])
{
      struct sigaction       nact,   /* new action  */
                             oact;   /* old action  */
nact.sa_handler =  (void(*)()) myfunc;
nact.sa_mask    =  0;
nact.sa_flags   =  SA_NOCLDSTOP;
       if (sigaction( SIGINT, &nact, &oact )!= 0) {
               perror("Sigaction: SIGINT ");
               exit(errno);
       }
}

From the Xinuos technical article database, record 100761. Reproduced with permission. The original is at www.sco.com/ta/100761, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.