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

This is a simple exercise to let you perfect the pattern of logging on, editing,

ID: 3909974 • Letter: T

Question


This is a simple exercise to let you perfect the pattern of logging on, editing, compiling. executing programs, and printing files from Linux. It is alse an opportunity for you to experiment with creating one process from within another Write the fork0 program to create 4 different process to carry on 4 different tasks You can use the code from class but personalize it so than' it is yours. All of your work must be done using allow you to get used to writing operating systems programs in CC+ and in a Linux environment. Your diligence in doing this very simple assignment will pay off for you in Linux unless otherwise stated. This a practke exereise to are not the main points of this assignment, it is expected that all of your work will be very neat and well programmed including an appropriate amount of comments and a prologue at the top of every function you write including the main function. Your prologue must contain your name, a brief description of what the function does, all pre-conditions, all post-conditions It should have a box drawn around it using comment symbols. It might look something ike the following For Example //Joe Smith Section#1 01-01.2020 This function is responsible for the following program porfoems a simple fork The return value of fork) is pid (defined in the libary header file

Explanation / Answer

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>

/*The Main Function Start*/
void main(int argc, char *argv[])
{
   /*Storing The Process Id*/
   pid_t pid;
   int j;
   int status = 0;

   int fd;
   pid = fork( );
   if (pid == 0){
      printf("Child 1: Sum of 2 and 3 is :%d ",5);
      exit(0);
   }
   else {
      pid = fork();
      if (pid == 0){
          printf("Child 2: Sum of 5 and 6 is :%d ",11);
          exit(0);
      }
      else {
         pid = fork();
         if (pid == 0){
            printf("Child 3: Sum of 7 and 8 is :%d ",15);
            exit(0);
         }
         else {
            pid = fork();
            if (pid == 0){
               printf("Child 4: Sum of 10 and 7 is :%d ",17);
               exit(0);
            }
            else {
              sleep(3);
               return;
            }
         }
      }
   }
}

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