25 lines
569 B
C
25 lines
569 B
C
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
void prepare() { printf("preparing for fork...\n"); }
|
|
|
|
void parent() { printf("in parent after fork...\n"); }
|
|
|
|
void child() { printf("in child after fork...\n"); }
|
|
|
|
int main() {
|
|
__register_atfork(prepare, parent, child);
|
|
pid_t pid = fork();
|
|
if (pid == 0) {
|
|
// in child process
|
|
printf("I am the child!\n");
|
|
} else {
|
|
// in parent process
|
|
printf("I am the parent!\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#pragma GCC diagnostic pop
|