Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error compiling process SIGALRM kill

Tags:

c

linux

fork

alarm

This program will create a child process, the child process will wait for an ALARM signal, when this signal arrives after 3 seconds, the f function will grab the parent process ID, and send a SIGINT signal to kill it, so the child will kill the parent after 3 seconds

#include <stdio.h>
    #include <unistd.h>
    #include <signal.h>
    #include <string.h>

    void f(int sig)
    {
        kill(getppid(),SIGINT);
    }

    main()
    {
        int f=fork();
        if(f==0)
        {
            signal(SIGALRM,f);
            alarm(3);
        }
        else
        {
            pause();
        }
    }

I got this error:

test13.c: In function ‘main’:
test13.c:16:3: warning: passing argument 2 of ‘signal’ makes pointer from integer without a cast
/usr/include/signal.h:101:23: note: expected ‘__sighandler_t’ but argument is of type ‘int’
like image 754
Ali Bassam Avatar asked Feb 20 '23 17:02

Ali Bassam


2 Answers

Stop stomping on f with your variable.

like image 193
Ignacio Vazquez-Abrams Avatar answered Mar 04 '23 09:03

Ignacio Vazquez-Abrams


You've reused the name f to refer to different things depending upon scope.

like image 28
sarnold Avatar answered Mar 04 '23 07:03

sarnold