Write a C program that has a local and a global variable. The
program uses a fork to create a child process. The parent process
modifies both variables to be 10 and 20 and prints out the values.
Then the child process modifies both variables to be 100 and 200
and prints out the values? Explain the program output?
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int globalVar = 1;
int main() {
int localVar = 2;
if(fork() == 0) {
// child process
globalVar = 100;
localVar = 200;
printf("Child process: Global: %d, Local: %d\n", globalVar, localVar);
} else {
// parent process
globalVar = 10;
localVar = 20;
printf("Parent process: Global: %d, Local: %d\n", globalVar, localVar);
}
waitpid(-1, NULL, 0);
return 0;
}

in case of any concerns, please let me know via comments.
Write a C program that has a local and a global variable. The program uses a...
Systems Programming Purpose: Understand the fork() regarding its returning values, global/local variables declared in the parent's process, and processing Instruction: Attached is a lab.c file containing a fork() statement. Compile and run it. Explain the output of this program. Thing to submit: Submit a word file to explain the following questions: When fork() is executed, what is happening to the returning values in parent and in child? After fork() is executed, how many more process is created? What is the...
Complete the following C code by filling all “???”sto write a C program to create a child process. Before the child process is created, an integer variable A is defined and assigned value 10. Then in the child process, A is reduced by 5. After the child process completes, the parent process increases A by 5. Then what will A’s value be just before the parent process completes? Why? Write the code and run it to verify your answer. #include...
Write a program using the fork() system call to do thefollowing. The parent process (main program) forks a process(CHILD 1) to compute and print the sum of first n integers where n is a variable shared between the parent and CHILD 1. Have the parent invoke the wait () call to wait for both the child processesto complete before exiting the program. IN A C program
a) Write a C-program that creates a chain of 10 processes and prints out their process ids and relationships. For example, process 1 is the parent of process 2, process 2 is the parent of process 3, process 3 is the parent of 4 and so on. Each child has to print out all her ancestors identified by the process ids. b) Write a C-program that creates a fan of 10 processes. That is, process 1 is the parent of...
Write a program that creates four processes. The original process creates two children processes and then prints out “parent”. The children processes print “child1” and “child2”, respectively. The first child process creates a child process that prints out “grandchild”. write a program that creates four processes. The original process creates two children processes and then prints out “parent”. The children processes print “child1” and “child2”, respectively. The first child process creates a child process that prints out “grandchild”. The output...
Write a program in C using the fork() system call to do the following. The parent process (main program) forks a process (CHILD 1) to compute and print the sum of first n integers where n is a variable shared between the parent and CHILD 1. It also forks another process (CHILD 2) that finds the sum of squares of the first n numbers where n is a variable it shares with the parent. Let CHILD 1 print “The sum...
Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is...
Q.5. (a) Write a program/ pseudo-code with following specs. The program contains an integer variable x initialized with value 20. After initializing x the program creates 07 processes using fork(). Each parent adds 10 to x and prints x. (15)
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...
follow the steps below to create a C program a) In the main function, fork a child process. b) In the child process, using an infinite loop to print out something. For example, you can print out the value of an int variable and each iteration increase the value of this int variable. You may also optionally sleep for a second or two in the loop to slow down the loop. c) In the parent process, sleep for a few...