Created
February 25, 2019 23:51
-
-
Save x42/60dfae7e5f2ec8cdb239087c324d10d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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