0

Alright, I was trying to make a simple function to constantly change its PID, but I get this:

error: ‘SIGKILL’ undeclared (first use in this function)

here is my code:

#include <stdio.h>

int changePID(void) {
        int pid = fork();
        printf(pid);
        sleep(3);
        kill(pid, SIGKILL);
}

    int main(void) {
        while (1) {
            changePID();
            }
}
Joe
  • 46,419
  • 33
  • 155
  • 245
D4zk1tty
  • 123
  • 1
  • 3
  • 15

3 Answers3

6

you are missing the line #include <signal.h> for the SIGKILL

printf(pid); is not going to work since printf need a char* and you give him a pid_t

What's the point of killing a child in a loop ?

printf is going to segv in the father so you will never reach kill

and in the son you are going to kill

every process in the process group of the current process with a pid of 0

Alexis
  • 2,149
  • 2
  • 25
  • 39
2

You need to add:

#include <sys/types.h>
#include <signal.h>

Look at the man page when you have an issue with a system call.

Benoit Thiery
  • 6,325
  • 4
  • 22
  • 28
0

try to include

#define <sys/signal.h>
Chirag Desai
  • 1,249
  • 1
  • 10
  • 22