Vuhelper
04-15-2011, 02:36 AM
Operating System- CS604
Assignment # 1
Spring 2011
Marks: 20
Due Date
Your assignment must be uploaded before or on April 18, 2011
Objective
The objective of this assignment is to familiarize with the system calls.
Instructions
Avoid Plagiarism. No marks will be given in case of cheating or copying from the
internet or from other students.
Submit the assignment through your account on VULMS. No assignment will be
accepted through email after the due date.
If you have any problem related to assignment, feel free to discuss it by email at
cs604@vu.edu.pk
Question # 1:
Read the following program carefully and write the output of the program. Explain each
line of code according to given numbering.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
1 int main (void)
{
pid_t pid;
2 pid = fork();
3 . if (pid > 0)
{
int i;
4 for (i = 0; i < 5; i++)
{
5 printf(" I AM VU : %d\n", i);
6 sleep(1);
}
exit(0);
}
7 else if (pid == 0)
{
int j;
for (j = 0; j < 5; j++)
{
8 printf(" I have no child: %d\n", j);
sleep(1);
}
_exit(0);
}
else
{
9 fprintf(stderr, "can't fork, error %d\n", errno);
10 exit (EXIT_FAILURE);
}
}
Assignment # 1
Spring 2011
Marks: 20
Due Date
Your assignment must be uploaded before or on April 18, 2011
Objective
The objective of this assignment is to familiarize with the system calls.
Instructions
Avoid Plagiarism. No marks will be given in case of cheating or copying from the
internet or from other students.
Submit the assignment through your account on VULMS. No assignment will be
accepted through email after the due date.
If you have any problem related to assignment, feel free to discuss it by email at
cs604@vu.edu.pk
Question # 1:
Read the following program carefully and write the output of the program. Explain each
line of code according to given numbering.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
1 int main (void)
{
pid_t pid;
2 pid = fork();
3 . if (pid > 0)
{
int i;
4 for (i = 0; i < 5; i++)
{
5 printf(" I AM VU : %d\n", i);
6 sleep(1);
}
exit(0);
}
7 else if (pid == 0)
{
int j;
for (j = 0; j < 5; j++)
{
8 printf(" I have no child: %d\n", j);
sleep(1);
}
_exit(0);
}
else
{
9 fprintf(stderr, "can't fork, error %d\n", errno);
10 exit (EXIT_FAILURE);
}
}