0% found this document useful (0 votes)
34 views4 pages

Os LB03

The document contains the source code and output for 4 programs that use the fork() system call in C to create child processes. Program 1 prints a message without using fork(). Program 2 prints a message before and after calling fork(). Program 3 calls fork() and the child process prints a different message than the parent. Program 4 calls fork() and both the child and parent process print their process IDs.

Uploaded by

Jawad Hussain
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)
34 views4 pages

Os LB03

The document contains the source code and output for 4 programs that use the fork() system call in C to create child processes. Program 1 prints a message without using fork(). Program 2 prints a message before and after calling fork(). Program 3 calls fork() and the child process prints a different message than the parent. Program 4 calls fork() and both the child and parent process print their process IDs.

Uploaded by

Jawad Hussain
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/ 4

Operating System 2017-SE-037

PROGRAM 01:
SOURCE CODE:
main()
{
printf("Operating System\n");
}

OUTPUT:

PROGRAM 02:
SOURCE CODE:
main()
{
printf("Operating System\n");
fork();
printf("After Fork()\n");
}
OUTPUT:

Name: Bilal Ali Section-A


Operating System 2017-SE-037

PROGRAM 03:
SOURCE CODE:
main()
{
int val;
printf("Another Program\n");
val=fork();
if(val==0)
printf("Child Class\n");
printf("After Fork Program\n");
}

OUTPUT:

Name: Bilal Ali Section-A


Operating System 2017-SE-037

PROGRAM 04:
SOURCE CODE:
main()
{
int val;
printf("Another Program\n");
val=fork();
if(val==0)
{
printf("%d"getpid());
printf("Child Class\n");
}
else
{
printf("Child Process Has Id:%d"val);
printf("Parent Process\n");
pid=getpid();
pritf("Process id:%d"pid);

Name: Bilal Ali Section-A


Operating System 2017-SE-037

}
}

OUTPUT:

Name: Bilal Ali Section-A

You might also like