Skip to content

Instantly share code, notes, and snippets.

@x42

x42/vforktest.c

Created Feb 25, 2019
Embed
What would you like to do?
// gcc -Wall -pthread -o vforktest vforktest.c
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
static void* run (void* arg)
{
for (int i = 0; i < 6; ++i) {
printf ("Test %d\n", i);
sleep (1);
}
return 0;
}
int main (int argc, char** argv)
{
pthread_t tid;
pthread_create (&tid, NULL, &run, NULL);
int pid = vfork ();
sleep (3);
if (pid == 0) {
execlp ("/bin/ls", "ls", (char*)NULL);
}
sleep (3);
pthread_join (tid, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.