Skip to content

Instantly share code, notes, and snippets.

@hfm
Created December 20, 2013 05:00
Show Gist options
  • Select an option

  • Save hfm/8050577 to your computer and use it in GitHub Desktop.

Select an option

Save hfm/8050577 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void child(void) {
int ret;
ret = execl("/usr/bin/touch", "touch", "test.txt", NULL);
if (ret == -1) {
perror("execv");
exit (EXIT_FAILURE);
}
}
int main(void) {
pid_t pid = fork();
if (pid > 0) {
printf("I am the parent of pid=%d!\n", pid);
} else if (!pid){
printf("I am the baby!\n");
} else if (pid == -1) {
perror("fork");
}
if (!pid) {
child();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment