/*
 * Problem 2-2
 */

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
	int i;
	
	/*
	 * First we output the "fater of all" :-)
	 * as the code in the textbook	
	 */
	printf("\n\nInitial process \t PID %6d \t PPID: %6d \t GID %6d \n\n", getpid(), getppid(), getpgid(0));
	
	for(i=0;i<3;++i)
	{
		if (fork() == 0)
		{	/*
			 * Here is the actual statement that 
			 * makes all the child processes become 
			 * group leaders of a group number that is
			 * the same as their PID
			 */
			setpgid(0,0);

			printf("New process \t PID %6d PPID %6d PGID %6d\n", getpid(), getgid(), getpgid(0)); 
		}
	}
}
/*
##### OUTPUT ######

adimitro@alef:/student/adimitro/cwork> ./a.out


Initial process          PID  16027      PPID:  15407    GID  16027

New process      PID  16028 PPID     20 PGID  16028
New process      PID  16030 PPID     20 PGID  16030
New process      PID  16031 PPID     20 PGID  16031
New process      PID  16029 PPID     20 PGID  16029
New process      PID  16032 PPID     20 PGID  16032
New process      PID  16033 PPID     20 PGID  16033
New process      PID  16034 PPID     20 PGID  16034
adimitro@alef:/student/adimitro/cwork>

*/
