Files
RedBear-OS/tests/unistd/fork.c
T
jD91mZM2 e35f22b3df WIP: pthread_atfork
WIP mainly because we *should* use thread locals, but #[thread_local]
causes segfaults.
2019-07-01 09:07:11 +02:00

30 lines
619 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "test_helpers.h"
void prepare() {
puts("Hello from prepare");
}
void parent() {
// Make sure we print in the right order and also don't exit
// before the fork does.
int us_status = usleep(1000);
ERROR_IF(usleep, us_status, == -1);
UNEXP_IF(usleep, us_status, != 0);
puts("Hello from parent");
}
void child() {
puts("Hello from child");
}
int main(void) {
int status = pthread_atfork(prepare, parent, child);
ERROR_IF(pthread_atfork, status, == -1);
int pid = fork();
ERROR_IF(fork, pid, == -1);
}