As I was compiling a simple program to try on the POSIX Signals, I encountered this error when I executed the program.
I was trying this out during lab session.
From what I understand is that I would send a kill with a pid to wake up the sleeping process and terminating it.
I'm pretty new at this topic so here's the code...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
typedef void Sigfunc(int);
int sigaction(int signum, const struct sigaction *newAction,
struct sigaction *oldAction);
Sigfunc *Signal(int signum, Sigfunc *signalHandler){
struct sigaction newAction, oldAction;
newAction.sa_handler = signalHandler;
sigemptyset(&newAction.sa_mask);
newAction.sa_flags = 0;
if(sigaction(signum, &newAction, &oldAction) < 0){
return(SIG_ERR);
}
else{
return(oldAction.sa_handler);
}
}
static void sigusr1_handler(int);
void mySIGUSR1Handler(int);
int main(void)
{
if(Signal(SIGUSR1, mySIGUSR1Handler) != SIG_IGN){
perror("ERROR");
}
if(Signal(SIGUSR1, SIG_IGN) != SIG_IGN){
if(Signal(SIGUSR1, mySIGUSR1Handler) != SIG_IGN){
perror("ERROR");
}
}
while(1)
pause();
}
void mySIGUSR1Handler(int signum){
fprintf(stderr, "Received signal SIGUSR1\n");
}
/****My Output
test: syntax error at line 1: `^?ELF^A^B^A^A^B^A^E\2144' unexpected
*************/
After the error is displayed, the program terminates after hitting the 'Enter' key.