0% found this document useful (0 votes)
39 views

Process Creation

This C code creates a new process using fork() and then the parent and child processes each write to standard output 200 times using a for loop. The output includes the process ID and iteration number to distinguish the parent and child output. getpid() is used to get the process ID to include in the output for identification.

Uploaded by

rajabala93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Process Creation

This C code creates a new process using fork() and then the parent and child processes each write to standard output 200 times using a for loop. The output includes the process ID and iteration number to distinguish the parent and child output. getpid() is used to get the process ID to include in the output for identification.

Uploaded by

rajabala93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

PROCESS CREATION

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#define MAX_COUNT 200
#define BUF_SIZE 100
void main(void)
{
pid_t pid;
int i;
char buf[BUF_SIZE];
fork();
pid = getpid();
for (i = 1; i <= MAX_COUNT; i++) {
sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
write(1, buf, strlen(buf));
}
}

You might also like