Demo entry 6737084

c

   

Submitted by anonymous on Apr 29, 2018 at 07:26
Language: C. Code size: 607 Bytes.

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int out;
    pid_t parent_pid = getpid();
    printf("Parent pid: %d\n", getpid());
    printf("The Group Id of parent process: %d\n", getpgid(0));
    pid_t new_pid = fork();

    if(!new_pid)//in child process
    {
        printf("In child process: %d\n", getpid());
        //create a new session
        printf("Create a session with child pid: %d\n", setsid());
        sleep(100);
        printf("111\n");
    }
    else
    {
        printf("In parent process: %d\n", getpid());
    }
    exit(0);
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).