Struggling to communicate between processes with signals - c

I'm trying to create a game in C under linux terminal.
I need to create a tetris game that consists of two c files,
One C file create execute file (a.out) and the other create (draw.out).
The first program create a child process and execute the other.
I need to send signals to the other program, but I found it difficult.
The source code is:
the first file-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <termios.h>
#include <signal.h>
char getch();
int main()
{
int fd[2],pid;
char *args[] = { "./draw.out", NULL },tav;
pipe(fd);
pid=fork();
if(pid==0)
{
execve("draw.out", args, NULL);
}
else
{
while(true)
kill(0,SIGUSR2);
}
return 1;
//getchar();
}
char getch() {
char buf = 0;
struct termios old = {0};
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
if (read(0, &buf, 1) < 0)
perror ("read()");
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror ("tcsetattr ~ICANON");
return (buf);
}
the second file-
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <signal.h>
typedef struct
{
int x;
int y;
}Point;
typedef struct
{
Point dots[3];
}Tool;
void drawBoard(int array[][20]);
void initBoard(int array[][20]);
Tool retrieveTool();
bool changeLocation(int array[][20],Tool* tool);
void my_handler(int signum);
int main()
{
bool nextTool=true;
Tool temp=retrieveTool();
int gameBoard[20][20];
signal(SIGUSR2, my_handler);
initBoard(gameBoard);
changeLocation(gameBoard,&temp);
drawBoard(gameBoard);
while(true)
{
signal(SIGUSR2, my_handler);
sleep(1);
system("clear");
if(!changeLocation(gameBoard,&temp))
temp=retrieveTool();
drawBoard(gameBoard);
}
return 1;
//getchar();
}
void initBoard(int array[][20])
{
bool isLast=false;
int i=0,j=0;
for(i=0;i<20;i++)
{
if(i==19)
isLast=true;
for(j=0;j<20;j++)
{
if((j==0)||(j==19)||(isLast))
array[i][j]=1;
else
array[i][j]=0;
}
}
}
void drawBoard(int symbols[][20])
{
int i=0,j=0;
for(i=0;i<20;i++)
{
for(j=0;j<20;j++)
if(symbols[i][j]==1)
printf("*");
else
if(symbols[i][j]==2)
printf("-");
else
printf(" ");
printf("\n");
}
}
Tool retrieveTool()
{
Tool temp;
int startX=0,startY=8,i=0;
for(i=0;i<3;i++)
{
temp.dots[i].x=startX;
temp.dots[i].y=startY;
startY++;
}
return temp;
}
bool changeLocation(int array[][20],Tool* tool)
{
int i=0;
for(i=0;i<3;i++)
{
if(array[tool->dots[i].x+1][tool->dots[i].y]!=0)
return false;
}
i=0;
for(i=0;i<3;i++)
{
array[tool->dots[i].x][tool->dots[i].y]=0;
if((tool->dots[i].x+1)==19)
tool->dots[i].x=-1;
tool->dots[i].x++;
array[tool->dots[i].x][tool->dots[i].y]=2;
}
return true;
}
void my_handler(int signum)
{
if (signum == SIGUSR2)
{
printf("Received SIGUSR1!\n");
}
}
The draw.out is the output file of the second file.
i created the signal handeler in the second file,
But the program still don't recieve the signal, what am i doing wrong?

This fragment:
while(true) kill(0,SIGUSR2);
has no sense. The kill should be used with the process id of the reveiver of SIGUSR2 (the child process in this case, identified by pid). Also note that an infinite loop sending signals to the child process is not what you want.
In the child process, you have an error in the print statement at signal handler:
printf("Received SIGUSR1!\n");
should be
printf("Received SIGUSR2!\n");
Depending on the OS version, you have to reinstall the signal handler once it gets called
Note: you are synchronizing processes, not threads

Related

Infinite loop terminating in pthread

#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <stdlib.h>
#include<signal.h>
#include<unistd.h>//getch();
#include <termios.h>//getch();
#include <pthread.h>
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
volatile sig_atomic_t flag = 0;
int value = 0;
int count = 0;
char getch()
{
int buf = 0;
struct termios old = { 0 };
fflush(stdout);
if (tcgetattr(0, &old) < 0)
perror("tcsetattr()");
old.c_lflag &= ~ICANON;
old.c_lflag &= ~ECHO;
old.c_cc[VMIN] = 1;
old.c_cc[VTIME] = 0;
if (tcsetattr(0, TCSANOW, &old) < 0)
perror("tcsetattr ICANON");
if (read(0, &buf, 1) < 0)
perror("read()");
old.c_lflag |= ICANON;
old.c_lflag |= ECHO;
if (tcsetattr(0, TCSADRAIN, &old) < 0)
perror("tcsetattr ~ICANON");
return buf;
}
void *send_function(void *parg)
{
printf("\n Send Thread ");
count++;
return parg;
}
void *receive_function(void *parg)
{
printf("\n Receive Thread ");
count++;
return parg;
}
void my_function(int sig)
{
flag = 1; // set flag
}
int main()
{
char selection; //user input(s or r)
pthread_t send;
pthread_t receive;
while (1)
{
signal(SIGINT, my_function);
if (flag)
{
printf("\n Choose your terminal S or R \n");
selection = getch();
flag = 0;
}
if (selection == 's')
{
if (pthread_create(&send, NULL, send_function, NULL))
{
printf("Error creating thread=%d\n", count);
return 1;
}
}
else if (selection == 'r')
{
if (pthread_create(&receive, NULL, receive_function, NULL))
{
printf("Error creating thread=%d\n", count);
return 1;
}
}
printf("\n MAIN LOOP\n");
//sleep(1);
}
return 0;
//pthread_exit(NULL);
}
Output1 :
MAIN LOOP
Receive Thread
MAIN LOOP
Receive Thread
MAIN LOOP
Receive Thread
MAIN LOOP
Receive Thread
Receive Thread
Receive Thread
Receive Thread Error creating thread=380
nivas#balakrishnan-HCL-Desktop:~/C_sample$
output2:
MAIN LOOP
MAIN LOOP
MAIN LOOP
Send Thread
Send Thread
Send Thread
Send Thread
Send Thread
MAIN LOOP
Error creating thread=379
In the above code. the code should run infinitely when I press 's' or 'r' it should print "send thread" or "receive thread" accordingly for infinite number of times whereas in this code approx 380 times only the while loop is running.I don't know why it is happening.I have used variable count for debugging purpose,can anyone help?
You need to either detach your threads or join them. Otherwise, you will run out of resources.

System Calls in C signals and fork

Hi I've this problem to solve with a functional program in C.
"Write a C program where a process F create a childprocess C.
The childprocess C waits the user to type the password, if is correct sends a signal SIGUSR1 to the father, if after 3 attempts the password is still incorrect it will send a SIGUSR2 signal to the father and terminate; if it receives from the father SIGUSR1 signal must stop viewing the "timeout" message.
His father after 30 seconds (if it has not received any signal from the child) must send the signal SIGUSR1 to the child and end with exit(1); if it receives the SIGUSR1 signal must end with exit(0); if it receives the signal SIGUSR2 must end with exit (2)."
I'm trying to solve it but I'm stuck. This is what I've done:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <signal.h>
void fatherprocess(int mysignal){
if (mysignal == SIGUSR1) {
printf("ACCESS GRANTED!\n");
exit(0);
}
if (mysignal == SIGUSR2){
printf("ACCESS DISCARDED! More than 3 tentatives!\n");
exit(2);
}
}
void childprocess(int mysignal){
if (mysignal == SIGUSR1) {
printf("TIMEOUT\n");
exit(1);
}
}
int main(int argc, char *argcv[]){
int fatherpid, childpid;
char enteredpassword[], password[] = "test";
int i =0;
unsigned int time_to_sleep = 30;
fatherpid = getpid();
childpid = fork();
if (childpid == 0) {
printf("Child Process waiting for a password\n");
while (1){
if (i < 3) {
printf("Enter Password: ");
scanf("%s", enteredpassword);
if (enteredpassword == password)
signal(SIGUSR1, fatherprocess);
} else {
signal(SIGUSR2, fatherprocess);
exit(1);
}
i++;
}
} else {
printf("Father Process\n");
while(time_to_sleep){
time_to_sleep = sleep(time_to_sleep);
signal(SIGUSR1, childprocess);
}
}
return 0;
}
I've edited my program in this way:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <signal.h>
void fatherprocess(int mysignal, int fatherpid){
if (mysignal == SIGUSR1) {
printf("ACCESS GRANTED!\n");
kill(fatherpid, SIGUSR1);
exit(0);
}
if (mysignal == SIGUSR2){
printf("ACCESS DISCARDED! More than 3 tentatives!\n");
kill(fatherpid, SIGUSR2);
exit(2);
}
}
void childprocess(int mysignal, int childpid){
if (mysignal == SIGUSR1) {
printf("TIMEOUT\n");
kill(childpid, SIGUSR1);
exit(1);
}
}
int main(int argc, char *argcv[]){
int fatherpid, childpid;
char enteredpassword[] = "test", password[] = "test";
int i =0;
unsigned int time_to_sleep = 30;
fatherpid = getpid();
childpid = fork();
if (childpid == 0) {
printf("Child Process waiting for a password\n");
while (1){
if (i < 3) {
printf("Enter Password: ");
scanf("%s", enteredpassword);
if (strcmp(enteredpassword, password) == 0)
fatherprocess(SIGUSR1, fatherpid);
} else {
fatherprocess(SIGUSR2, fatherpid);
exit(1);
}
i++;
}
} else {
printf("Father Process\n");
while(time_to_sleep){
time_to_sleep = sleep(time_to_sleep);
childprocess(SIGUSR1, childpid);
}
}
return 0;
}
Now it works perfectly but I don't know if I've respected the exercise text.
As was mentioned in the comments (by Jonathan Leffler), you need to use the kill() system call (to send the signals) and register a signal handler using a call like sigaction(). I have linked these two calls to online manual pages that provide additional information about them.
Here's some code that demonstrates how these can be used towards achieving your stated goal. You will still need to add/modify the code for things like the prompts you want and the acceptable input string. Please note that I'm not claiming this to be the best way to do it, only that it's an example of how it could be done (it compiled and worked for me):
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
static void get_password(char* buf, int maxbuf)
{
fgets(buf, maxbuf, stdin);
}
static int is_password_correct(char* buf)
{
return buf[0] == 'a';
}
volatile int got_signal = 0;
volatile int child_signal = 0;
static void parent_sig_handler(int signum)
{
if (!got_signal)
{
got_signal = signum;
printf("parent_sig_handler: got sig %d\n", signum);
}
}
static void child_sig_handler(int signum)
{
if (!child_signal)
{
child_signal = signum;
printf("child_sig_handler: got sig %d\n", signum);
}
}
int main()
{
struct sigaction act;
sigfillset(&act.sa_mask);
act.sa_handler = parent_sig_handler;
sigaction(SIGALRM, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
pid_t child_pid = fork();
if (child_pid == -1)
{
perror("error forking");
exit(3);
}
if (child_pid == 0)
{
printf("child running\n");
act.sa_handler = child_sig_handler;
sigaction(SIGUSR1, &act, NULL);
pid_t parent_pid = getppid();
for (int i = 0; i < 3; ++i)
{
char passwd[64];
passwd[0] = '\0';
get_password(passwd, sizeof(passwd));
if (is_password_correct(passwd))
{
kill(parent_pid, SIGUSR1);
exit(0);
}
}
kill(parent_pid, SIGUSR2);
exit(2);
}
printf("parent running\n");
alarm(30); /* sets parent up to receive a SIGALRM signal in 30 seconds */
sigset_t sigmask;
sigemptyset(&sigmask);
while (!got_signal)
{
sigsuspend(&sigmask);
}
switch (got_signal)
{
case SIGALRM:
kill(child_pid, SIGUSR1);
exit(1);
case SIGUSR1:
exit(0);
case SIGUSR2:
exit(2);
default:
exit(3);
}
exit(3);
}

process communication with signls

I am trying to write a C program which has some number of processes. One of them sends a random signal in the range SIGRTMIN and SIGRTMAX to all other processes but I want this signal will be ignored in main process.I used the global variable to have randomized signal to ignore with SIG_IGN. It looks It is not helping because the main stops with real-time signal when wants to ignore the first randomized signal.
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <time.h>
volatile sig_atomic_t disarming_signal = 0;
void disarming_handler (int sig) {
disarming_signal = sig;
fprintf(stderr,"signal %d is handeled", disarming_signal);
}
int rand_range(int min_n, int max_n){
int rand_n = rand() % (max_n - min_n) + min_n;
return rand_n;
}
int sethandler (void (*f)(int), int sigNo) {
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = f;
if (-1==sigaction(sigNo, &act, NULL))
return -1;
return 0;
}
void sigchld_handler(int sig){
pid_t pid;
for(;;){
pid=waitpid(0, NULL, WNOHANG);
if(pid==0) return;
if(pid<=0) {
if(errno==ECHILD) return;
perror("waitpid:");
exit(EXIT_FAILURE);
}
}
}
void usage(){
fprintf(stderr,"USAGE: sappartherroryst n\n");
fprintf(stderr,"n - number of Therrorysts\n");
}
void therroryst_work(){
int s,k,t;
srand(getpid());
s = rand_range(SIGRTMIN, SIGRTMAX);
t = rand_range(10, 20);
k = t;
if(sethandler(disarming_handler, s)){
perror("Seting therroryst handeler");
exit(EXIT_FAILURE);
}
fprintf(stderr, "[%d] I am therroryst. My disarming signal is [%d]. I will wait [%d] Sec.\n", getpid(), s, t);
while(k>0) {
k=sleep(k);
if(disarming_signal == s){
fprintf(stderr, "I got signal [%d]\n.",disarming_signal);
return ;
}
}
fprintf(stderr, "[%d] KABOOM\n",getpid());
exit(EXIT_SUCCESS);
}
void create_therrorysts(int n){
while(n-->0){
switch(fork()) {
case 0:
therroryst_work();
exit(EXIT_SUCCESS);
case -1:
perror("Fork():");
exit(EXIT_FAILURE);
}
}
}
void sapper_work(){
int sig_dis, i;
struct timespec t, tn = {1,0};
fprintf(stderr,"[%d] I am sapper.\n", getpid());
for(i=0;i<10;i++){
for(t=tn;nanosleep(&t,&t););
sig_dis = rand_range(SIGRTMIN, SIGRTMAX);
if(kill(0, sig_dis)<0){
perror("Disarming_send\n");
exit(EXIT_FAILURE);
}
fprintf(stderr,"I sended signal [%d].\n",sig_dis);
disarming_signal = sig_dis;
}
fprintf(stderr, "end of sending");
exit(EXIT_SUCCESS);
}
void create_sapper(){
switch(fork()) {
case 0:
sapper_work();
exit(EXIT_SUCCESS);
case -1:
perror("Fork():");
exit(EXIT_FAILURE);
}
}
int main(int argc, char** argv){
int n;
pid_t pid;
if(argc != 2){
usage();
return EXIT_FAILURE;
}
n = atoi(argv[1]);
if(n <= 0){
usage();
return EXIT_FAILURE;
}
if(sethandler(sigchld_handler, SIGCHLD)) {
perror("Seting parent SIGCHLD:");
exit(EXIT_FAILURE);
}
create_therrorysts(n);
create_sapper();
sleep(5);
for(;;) {
if(sethandler(SIG_IGN, disarming_signal)){
perror("Seting parent disarming111");
exit(EXIT_FAILURE);
}
}
for(;;){
pid=wait(NULL);
if(pid<0)
switch (errno){
case ECHILD:
return EXIT_SUCCESS;
case EINTR:
continue;
default:
perror("wait:");
exit(EXIT_FAILURE);
}
}
return EXIT_SUCCESS;
}
You have sleep(5) after the create_sapper and before sethandler(IGN). That means it's very likely that the signal is sent before your main process has ignored it.
EDIT: Adding comment from Jonathan Leffler into this answer as it is equally (or even more) important:
There's also a problem with setting the signal handler even if you put the sleep() after that loop - the parent doesn't get to see what the child chooses as disarming_signal.

is SIGINT semi blocking possible?

Im trying to handle SIGINT. Main purpose of SIGINT in my program cancelling current search function and printing the currently avaliable results. But whenever I try to catch a SIGINT signal it just closes my program. (I ve searched so much ,please just do not say that I have not searched enough)
I have tried :
basic signal handling(as shown as below)
sigaction functionality
non-local signal handling
sigprocmask (problem with procmask whenever I block a signal I cannot catch it but I need to catch and make printing on screen)
after all i have run out of search keyword to find a solution. Any idea ? (search keyword or part of code or logic way to do it ^^)
NOTE : This text may have grammar errors. Sorry for any mistakes.
#ifdef DEBUG
#define DPRINT(file ,message ,arg) fprintf(file ,message ,arg);
#define NDPRINT(file ,message) fprintf(file ,message);
#endif
static volatile sig_atomic_t isSignalCaught = 0;
void SIGHandler(int signo);
int main(int argc, char** argv)
{
file_t *files,*nextP;
signal(SIGINT, SIGHandler);
files = findFiles("/");
while (files != NULL) {
DPRINT(stderr, "%s\n", files->fileName.string);
nextP = files->pNext;
free(files->fileName.string);
free(files);
files = nextP;
}
return(0);
}
void SIGHandler(int signo)
{
file_t *nextP;
if (signo == SIGINT) {
isSignalCaught = 1;
}
}
Here's an example of how to do what I think you want to do.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <ctype.h>
typedef void(* sig_func_t )(int);
volatile sig_atomic_t keep_looping = 1;
void sig_handler(int sig_number) {
switch (sig_number) {
case SIGINT:
keep_looping = 0;
break;
}
}
int should_continue(void) {
char line[256];
while (1) {
printf("Continue? (y/n) ");
fgets(line, sizeof line, stdin);
if (tolower(line[0]) == 'y') {
keep_looping = 1;
signal(SIGINT, sig_handler);
return 1;
}
if (tolower(line[0]) == 'n')
break;
}
return 0;
}
int main (void) {
sig_func_t sig_func;
sig_func = signal(SIGINT, sig_handler);
if (sig_func == SIG_ERR) {
perror("signal");
exit(EXIT_FAILURE);
}
unsigned n = 0;
printf("Starting...\n");
while (1) {
while (keep_looping)
n++;
printf("Current value: n=%u\n", n);
if (!should_continue())
break;
}
signal(SIGINT, sig_func);
return EXIT_SUCCESS;
}

Some wrong about sigsetjmp

I am reading the APUE, Chapter 10. Here is my code.
#include "apue.h"
#include <unistd.h>
#include <setjmp.h>
#include <time.h>
#include <errno.h>
static void sig_usr1(int), sig_alrm(int);
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjmp;
int
main(void)
{
if(signal(SIGUSR1, sig_usr1) == SIG_ERR)
err_sys("signal(SIGUSR1) error");
if(signal(SIGALRM, sig_alrm) == SIG_ERR)
err_sys("signal(SIGALRM) error");
//print signal.
pr_mask("Starting main: ");
if(sigsetjmp(jmpbuf, 1)) {
pr_mask("End main: ");
exit(0);
}
canjmp = 1;
for(;;)
pause();
}
static void
sig_usr1(int signo)
{
time_t starttime;
if(canjmp == 0) {
return;
}
pr_mask("starting sig_usr1: ");
alarm(3);
starttime = time(NULL);
for(;;)
if(time(NULL) > starttime + 5)
break;
pr_mask("finishing sig_usr1: ");
canjmp = 0;
siglongjmp(jmpbuf, 1);
}
static void
sig_alrm(int signo)
{
pr_mask("in sig_arlm: ");
}
void
pr_mask(const char *str)
{
sigset_t sigset;
int errno_save;
errno_save = errno; /* we can be called by signal handlers */
if (sigprocmask(0, NULL, &sigset) < 0)
err_sys("sigprocmask error");
printf("%s", str);
if (sigismember(&sigset, SIGUSR1)) printf("SIGUSR1 ");
if (sigismember(&sigset, SIGALRM)) printf("SIGALRM ");
/* remaining signals can go here */
printf("\n");
errno = errno_save;
}
I thought the output would be like this:
Starting main:
starting sig_usr1: SIGUSR1
in sig_alrm: SIGUSR1 SIGALRM
finishing sig_usr1: SIGUSR1
End main:
but it seems something wrong, this is my output in fact:
Starting main:
starting sig_usr1:
in sig_alrm:
finishing sig_usr1:
End main:
that is no signals. Please help me.
I think the trouble is probably that you are using signal() and not sigaction() to set the signal handling. And signal() does not mask any other signals - so there are no signals to show as being blocked. I modified your code as shown below, to use signal() and sigaction() depending on whether there are any arguments or not.
#include <signal.h>
#include <unistd.h>
#include <setjmp.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
typedef void (*Handler)(int);
static void sig_usr1(int), sig_alrm(int);
static sigjmp_buf jmpbuf;
static volatile sig_atomic_t canjmp;
static void pr_mask(const char *str);
static void err_sys(const char *str)
{
int errnum = errno;
fprintf(stderr, "%s (%d: %s)\n", str, errnum, strerror(errnum));
exit(1);
}
static void set_sigaction(int signum, Handler handler)
{
struct sigaction nact;
nact.sa_handler = handler;
sigfillset(&nact.sa_mask);
//sigemptyset(&nact.sa_mask);
nact.sa_flags = 0;
if (sigaction(signum, &nact, 0) != 0)
err_sys("Failed to set signal handling");
}
int
main(int argc, char **argv)
{
printf("PID = %u\n", (unsigned)getpid());
if (argc > 1)
{
if (signal(SIGUSR1, sig_usr1) == SIG_ERR)
err_sys("signal(SIGUSR1) error");
if (signal(SIGALRM, sig_alrm) == SIG_ERR)
err_sys("signal(SIGALRM) error");
}
else
{
set_sigaction(SIGUSR1, sig_usr1);
set_sigaction(SIGALRM, sig_alrm);
}
//print signal.
pr_mask("Starting main: ");
if (sigsetjmp(jmpbuf, 1)) {
pr_mask("End main: ");
exit(0);
}
canjmp = 1;
for (;;)
pause();
}
static void
sig_usr1(int signo)
{
time_t starttime;
if (canjmp == 0) {
return;
}
pr_mask("starting sig_usr1: ");
alarm(3);
starttime = time(NULL);
for (;;)
if (time(NULL) > starttime + 5)
break;
pr_mask("finishing sig_usr1: ");
canjmp = 0;
siglongjmp(jmpbuf, 1);
}
static void
sig_alrm(int signo)
{
pr_mask("in sig_arlm: ");
}
void
pr_mask(const char *str)
{
sigset_t sigset;
int errno_save;
errno_save = errno; /* we can be called by signal handlers */
if (sigprocmask(0, NULL, &sigset) < 0)
err_sys("sigprocmask error");
printf("%s", str);
if (sigismember(&sigset, SIGUSR1)) printf("SIGUSR1 ");
if (sigismember(&sigset, SIGALRM)) printf("SIGALRM ");
/* remaining signals can go here */
printf("\n");
errno = errno_save;
}
Running on MacOS X 10.7.2 with current XCode (4.2?), I get (for example):
$ ./sigtest
PID = 11066
Starting main:
starting sig_usr1: SIGUSR1 SIGALRM
finishing sig_usr1: SIGUSR1 SIGALRM
in sig_arlm: SIGUSR1 SIGALRM
End main:
$ ./sigtest 1
PID = 11067
Starting main:
starting sig_usr1: SIGUSR1
in sig_arlm: SIGUSR1 SIGALRM
finishing sig_usr1: SIGUSR1
End main:
$

Resources