Question

Part A:Write a C program called createProcesses.c to implement the following diagram: exit(0) fork() exit(0) fork() exit(0) f

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

Part A:

Since there is nothing mentioned in the Question, so I am using Linux environment for coding and testing:
Step 1
Go to gedit
Create createProcesses.c and enter the program code

#include <stdio.h> //Library function inclusion
#include <conio.h> //Library function inclusion
#include <sys/types.h> //Library function inclusion
#define MAX_COUNT 10 //Macro definition
void ChildPro1(); //First child process function with return type void
void ChildPro2(); //Second child process function with return type void

void main() //Main function with void return type
{
pid_t pid; // Process id variable creation
pid = fork(); //Creation of process
if (pid == 0) //Condition check
{
ChildPro1(); //Calling first child function
ChildPro2(); //Calling second child function

}

else //Else condition

exit(0); //Exit

}

void ChildPro1() //First child function with void return type
{
int i; //Integer declaration
for (i = 1; i <= MAX_COUNT; i++) //Loop from 1 to maximum count variable
printf("Child1 executing for %d time\n", i); //Print command
printf("Child1 is completed"); //Print command

exit(0); //Exit
}

void ChildPro2() //Second child function with void return type
{
int i; //Integer declaration
for (i = 1; i <= MAX_COUNT; i++) //Loop from 1 to maximum count variable
printf("Child2 executing for %d time\n", i); //Print command
exit(0); //Exit
}

Step 2: Output

Please enter the command below to execute the program

gcc -o createProcesses.c

Part B:

Fork() function is used in operating system to create a process. For a fork() call of n times, 2n-1 processes are created. For this question purpose this should be sufficient. I can't provide the sample output here but I have checked and it is working fine.

Thankyou.....////

Add a comment
Know the answer?
Add Answer to:
Part A:Write a C program called createProcesses.c to implement the following diagram: exit(0) for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement the C code that would generate the following sequence diagram for process creation. You...

    Implement the C code that would generate the following sequence diagram for process creation. Your code should output the pid of each process (print the return value from getpid once in each process) as it is created. Make sure you keep track of what process you're in at any given time, and that your calls to fork are in the correct spot. (Also, ensure that you are checking if each call to fork succeeded or not and printing an appropriate...

  • c++ program Implement a class called Person with the following members: 1a. ????, a private variable...

    c++ program Implement a class called Person with the following members: 1a. ????, a private variable of type ?????? 1b. ???, a private variable of type ??? 1c. Default constructor to set name to "" and age to 0 1d. Non-default constructor which accepts two parameters for name and age 1e. A copy constructor 1f. The post-increment operator 1g. The pre-decrement operator 1h. The insertion and extraction stream operators >>and <<

  • Write a C program for Linux called pipes.c that does the following: In the main() function,...

    Write a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe using the pipe() function, then creates two child processes with fork(). Child 1 redirects stdout to the write end of the pipe and then executes with execlp() the "ps -aux" command. Child 2 redirects its input from stdin to the read end of the pipe, then it executes the "sort -r -n -k 5" command. After creating both children, the...

  • Overview Writing in the C language, implement a very basic shell, called smash. In this project,...

    Overview Writing in the C language, implement a very basic shell, called smash. In this project, we will work on processing strings and using the appropriate system calls. Build System setup Before we can start writing code we need to get our build system all setup. This will involve writing a very simple makefile. You should leverage your Makefile project for this part of the assignment! Write a Makefile that provides the three targets listed below all - The default...

  • Write the following program in C Language using standard library functions. /*Implement the Find function, called...

    Write the following program in C Language using standard library functions. /*Implement the Find function, called in the program below. This function receives two strings, and looks for the first occurrence of the second string in the first string, returning the number of characters it is in, relative to the beginning of the first string. If not, returns -1. In the program, a string with two news headlines is given, and the sub-strings "iPad" and "Huawei” are searched for, having...

  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • Suppose that you have three programs that are suppose to print a house diagram in a...

    Suppose that you have three programs that are suppose to print a house diagram in a collaborative manner. (i) prog1.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“                      ^^^^^^^^^^^^                       \n”);     printf(“           ^^^^^^^^^^^            ^^^^^^^^^^^            \n”);     printf(“^^^^^^^^^^^                                  ^^^^^^^^^^^ \n”);     printf(“     |                                            |      \n”);     printf(“     |                                            |      \n”);     exit(1); } (i) prog2.c #include <stdio.h>      /* Input/Output */ #include <stdlib.h>     /* General Utilities */ int main() {     printf(“     |                                             |    ...

  • 3. write a c++ program: Design and implement a class called Clock that describes the time...

    3. write a c++ program: Design and implement a class called Clock that describes the time of a clock: a) Include in the class 3 constructors with one, two, and three parameters to set the hours, the minutes, and the seconds, respectively. b) Include also a default constructor that sets the member variables of the class to 00:00:00. c) Write a member function to increment the time by a given amount, and second member function to reset the clock. The...

  • Design and implement C/C++ program (myshell5.c) to process command (to tokenize and parse the command, and...

    Design and implement C/C++ program (myshell5.c) to process command (to tokenize and parse the command, and print its components correctly). Your C/C++ program should be able to parse each command from user (to process one command after the other in a loop), until the user's command entered is "exit" to terminate the program. Examples (You may create your own output format or template to show the command(s) being parsed.) Run your program for each of the following examples, to show...

  • C program To develop a C program to implement a process system call. PROBLEM You are...

    C program To develop a C program to implement a process system call. PROBLEM You are to use the Ubuntu operating system to write a C program that creates a process to determine the identification of the current user of your computer. I mean if joe is the login of the current user of your computer your solution should return joe. Your solution must also provide the pid of both the parent and the child processes. You may use the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT