Skip to content

Instantly share code, notes, and snippets.

@tobert
Created February 1, 2011 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobert/806798 to your computer and use it in GitHub Desktop.
Save tobert/806798 to your computer and use it in GitHub Desktop.
Test the nsfork() function.
/* 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