Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program Assignment 1: Process Management Due by Feb. 26th, 2017 Credit: 15 point

ID: 3794136 • Letter: P

Question

Program Assignment 1: Process Management

Due by Feb. 26th, 2017

Credit: 15 points

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.

iii. For extra credit, you can also incorporate advanced features, like socket or thread functions, into your code.

Explanation / Answer

#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{
    printf("--beginning of program ");

    int counter = 0;
    pid_t pid = fork();

    if (pid == 0)
    {
        // child process
        int i = 0;
        for (; i < 5; ++i)
        {
            printf("child process: counter=%d ", ++counter);
        }
    }
    else if (pid > 0)
    {
        // parent process
        int j = 0;
        for (; j < 5; ++j)
        {
            printf("parent process: counter=%d ", ++counter);
        }
    }
    else
    {
        // fork failed
        printf("fork() failed! ");
        return 1;
    }

    printf("--end of program-- ");

    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote