CS604 Assignment 1 Solution Fall 2017

CS604 Assignment 1 Solution fall 2017

cs604 assignment 1 solution

cs604 assignment 1 solution, assignment solution cs604, cs604, cs604 assignment 1, cs604 assignment 1 solution, cs604 assignment 1 solution 2017, cs604 assignment solution, cs604 assignment solution 2017, cs604 assignment 1 solution fall 2017, cs604 assignment 1 solution

 

Question Marks 20

Problem Statement:

You are required to write a simple C language program to:
Create a process using fork call
Get and print status information about the running processes
Use pipe call for inter-process communication between processes
Terminate process
Compile & run C program on Linux Operating system.
Detailed Description:

In the main() function, first of all you will establish a channel for processes to communicate through pipe system call. After successful creation of pipe, you will create child process through fork() system call.

In the child process, you will have to display your own student Id through the pipe or channel established between processes. In the parent process, you will have to display your own student name through the pipe or channel established between processes.

You will also print the status information of Parent and Child process by using user-defined function printInfo(). The status information includes Process Id and Parent Id in case of Child process and Process ID and Child Id in case of Parent process.

Compilation & Execution of Program:

You will compile your file with your student ID. For example, if your student ID is BC123456789 then you will compile the code according to following screenshot.

 

CS604 Assignment 1 Solution

Due Date 13-11-2017

 

#include <stdio.h>
#include <sys/types.h>
int main()
{
int macrotechx[2];
pid_t pid;
pipe(macrotechx);// creating pipe
pid=fork(); // child process
if(pid==0){
 printf("Student ID: macrotechx786\n");
 printinfo("child Process");
 printf("Student Name: macrotechx solutions\n");
 close(macrotechx[0]); // Termenating the child process.
 }
 else {
 printinfo("Parent Process");
 } 
}
void printinfo(char pname[])
{
 
 printf("Process name: %s\n",pname);
 printf("My process ID : %d\n", getpid());
 printf("My parent's ID: %d\n", getppid()); 
 
}

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: