1. Homepage
  2. Exam
  3. COMP2017/9017 System Programming - Sample Exam - Q9 Interprocess Communication

COMP2017/9017 System Programming - Sample Exam - Q9 Interprocess Communication

This question has been solved
Engage in a Conversation

Question 9 (Concurrency) (15 marks)

  CourseNana.COM

Write in ANSWER BOOKLET CourseNana.COM

  CourseNana.COM

You are to create an interprocess communication mechanism. CourseNana.COM

  CourseNana.COM

A program’s initial process, P0, creates and maintains a stack data structure. Many child processes are CourseNana.COM

created thereafter and they rely on the same stack data structure of the parent process P0. CourseNana.COM

  CourseNana.COM

Only the parent process P0 can modify the stack contents. Any child process can operate on the stack CourseNana.COM

by communicating with P0. CourseNana.COM

  CourseNana.COM

There are two types of child processes: CourseNana.COM

• Worker - performs operations with the stack if is is not full or not empty. CourseNana.COM

• Cleaner - performs operations with the stack when it is full or when it is empty. The cleaner aims to make the stack non-empty and non-full. CourseNana.COM

Cleaner processes cannot operate on the stack while Worker processes operate and vice versa. CourseNana.COM

  CourseNana.COM

The stack operations are as follows: CourseNana.COM

  CourseNana.COM

// places the integer x on top of the stack CourseNana.COM

// Otherwise , err is set to non -zero value if the stack is full CourseNana.COM

void push( struct stack *, int x, int *err ); CourseNana.COM

// removes and returns the integer on top of the stack CourseNana.COM

// Otherwise , err is set to non -zero value if the stack is empty CourseNana.COM

int pop( struct stack *, int *err ); CourseNana.COM

// returns the integer on top of the stack CourseNana.COM

// Otherwise , err is set to non -zero value if the stack is empty CourseNana.COM

int peek( struct stack *, int *err ); CourseNana.COM

// returns non -zero value when empty CourseNana.COM

int is_empty( ); CourseNana.COM

  CourseNana.COM

Describe interprocess communication necessary to keep the stack synchronised for N child processes, where child processes can be either Worker or Cleaner types. CourseNana.COM

  CourseNana.COM

You can describe your answer with pseudocode, or C code (most accurate). If your answer is not clear, marks can be deducted. CourseNana.COM

  CourseNana.COM

Useful functions for your reference: CourseNana.COM

  CourseNana.COM

Setting the signal handler CourseNana.COM

typedef void (*sighandler_t)(int); CourseNana.COM

sighandler_t signal(int signum, sighandler_t handler); CourseNana.COM

  CourseNana.COM

Sets the disposition of the signal signum to handler, which is either SIG_IGN, SIG_DFL, or the CourseNana.COM

address of a programmer defined function (a "signal handler"). CourseNana.COM

  CourseNana.COM

signal() returns the previous value of the signal handler, or SIG_ERR on error. CourseNana.COM

  CourseNana.COM

Sending the signal CourseNana.COM

int raise(int sig); CourseNana.COM

  CourseNana.COM

Sends a signal to the calling process or thread. If the signal causes a handler to be called, raise() will return only after the signal handler has returned. raise() returns 0 on success, and nonzero for failure. CourseNana.COM

  CourseNana.COM

Setting up the pipe CourseNana.COM

int pipe(int pipefd[2]); CourseNana.COM

creates a pipe, a unidirectional data channel that can be used for interprocess communication. CourseNana.COM

  CourseNana.COM

The array pipefd is used to return two file descriptors referring to the ends of the pipe. CourseNana.COM

pipefd[0] refers to the read end of the pipe. pipefd[1] refers to the write end of the pipe. CourseNana.COM

On success, zero is returned. On error, -1 is returned. CourseNana.COM

Get the Solution to This Question

WeChat WeChat
Whatsapp WhatsApp
System Programming代写,C Language代写,Memory代写,Pointer代写,Parallelisation代写,Interprocess Communication代写,System Programming代编,C Language代编,Memory代编,Pointer代编,Parallelisation代编,Interprocess Communication代编,System Programming代考,C Language代考,Memory代考,Pointer代考,Parallelisation代考,Interprocess Communication代考,System Programminghelp,C Languagehelp,Memoryhelp,Pointerhelp,Parallelisationhelp,Interprocess Communicationhelp,System Programming作业代写,C Language作业代写,Memory作业代写,Pointer作业代写,Parallelisation作业代写,Interprocess Communication作业代写,System Programming编程代写,C Language编程代写,Memory编程代写,Pointer编程代写,Parallelisation编程代写,Interprocess Communication编程代写,System Programmingprogramming help,C Languageprogramming help,Memoryprogramming help,Pointerprogramming help,Parallelisationprogramming help,Interprocess Communicationprogramming help,System Programmingassignment help,C Languageassignment help,Memoryassignment help,Pointerassignment help,Parallelisationassignment help,Interprocess Communicationassignment help,System Programmingsolution,C Languagesolution,Memorysolution,Pointersolution,Parallelisationsolution,Interprocess Communicationsolution,