Program Assignment 1: Process Management
Objective: This program assignment is given to the Operating Systems course to allow the students to figure out how a single process (parent process) creates a child process and how they work on Unix/Linux(/Mac OS X/Windows) environment. Additionally, student should combine the code for describing inter-process communication into this assignment. Both parent and child processes interact with each other through shared memory-based communication scheme or message passing scheme.
Environment: Unix/Linux environment (VM Linux or Triton Server, or Mac OS X), Windows platform Language: C or C++, Java Requirements:
i. You have wide range of choices for this assignment. First, design your program to explain the basic concept of the process management in Unix Kernel. This main idea will be evolved to show your understanding on inter-process communication, file processing, etc.
ii. Refer to the following system calls: - fork(), getpid(), family of exec(), wait(), sleep() system calls for process management - shmget(), shmat(), shmdt(), shmctl() for shared memory support or - msgget(), msgsnd(), msgrcv(), msgctl(), etc. for message passing support
iii. The program should present that two different processes, both parent and child, execute as they are supposed to.
iv. The output should contain the screen capture of the execution procedure of the program.
v. Interaction between parent and child processes can be provided through inter-process communication schemes, such as shared-memory or message passing schemes.
vi. Result should be organized as a document which explains the overview of your program, code, execution results, and the conclusion including justification of your program, lessons you've learned, comments, etc. Note: i. In addition, please try to understand how the local and global variables work across the processes ii. read() or write () functions are used to understand how they work on the different processes.
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
printf("--beginning of program\n");
int counter = 0;
pid_t pid = fork();
if (pid == 0)
{
// child
process
int i = 0;
for (; i < 5;
++i)
{
printf("child
process: counter=%d\n", ++counter);
}
}
else if (pid > 0)
{
// parent
process
int j = 0;
for (; j < 5;
++j)
{
printf("parent
process: counter=%d\n", ++counter);
}
}
else
{
// fork
failed
printf("fork()
failed!\n");
return 1;
}
printf("--end of program--\n");
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.