Created
February 1, 2011 22:02
-
-
Save tobert/806798 to your computer and use it in GitHub Desktop.
Test the nsfork() function.
This file contains 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
/* must run as root or with CAP_SYS_ADMIN | |
* e.g. sudo ./test_nsfork | |
* or | |
* sudo | |
*/ | |
#include "nsfork.h" | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
pid_t child; | |
child = nsfork(0); | |
// parent process | |
if (child > 0) | |
printf("one: %d\n", getpid()); | |
// child process | |
else if (child == 0) | |
printf("two: %d\n", getpid()); | |
// error - probably missing capabilities | |
else | |
printf("error in nsfork(): probably lacking privileges or running on an old kernel\n"); | |
/* printf("Child value is %d in process %d\n", child, getpid()); */ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment