Skip to content

Instantly share code, notes, and snippets.

@geekuillaume
Created June 13, 2014 20:01
Show Gist options
  • Save geekuillaume/4f024664647bc3b7cd4e to your computer and use it in GitHub Desktop.
Save geekuillaume/4f024664647bc3b7cd4e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int main()
{
gid_t gid;
int childPID;
printf("Start PID : %d\n", getpid());
printf("Start GPID : %d\n", getpgrp());
gid = 0;
if ((childPID = fork()) == -1)
perror("fork failed");
if (childPID == 0)
{
setsid();
printf("Child GPID : %d\n", getpgrp());
while (1)
{
printf("Child still here...\n");
sleep(1);
}
}
else
{
printf("Parent GPID : %d\n", getpgrp());
while (1)
{
printf("Parent still here...\n");
sleep(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment