#include <sys/types.h> #include <stdio.h> #include <unistd.h> int value = 10; int main() { pid_t pid; pid = fork(); if (pid == 0) { value = value + 100; } else if (pid > 0) { value = value -100; printf("PARENT: value= %d \n", value); //Line A wait (NULL); } } (i) What will be the output in Line A? Justify your answer. (ii) Do you think there is synchronization problem in updating the variable value? Justify your answer.
We need at least 9 more requests to produce the answer.
1 / 10 have requested this problem solution
The more requests, the faster the answer.
Problem la Points (20) Draw the process tree for the program shown below. #include<sys/types.h> #include<stdio.h> #include<unistd.h> int value = 5; int main() pid_t pid; pid = forko; if(pid ==0) { */ Child Process */ forkO; value += 15; return 0; else if (pid > 0) {/* Parent process */ forkO; forkO; wait(NULL); printf("Parent: value = %d", value); /* LINE A */ return 0;
Source code to modify:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int main()
{
pid_t pid;
/*fork a child process*/
pid = fork();
if (pid<0){ /*error occured*/
fprintf(stderr,"Fork failed\n");
return 1;
}
else if (pid == 0) { /*child process */
printf("I am the child %d\n",pid);
execlp("/bin/ls","ls",NULL);
}
else { /*parent process */
/*parent will wait for the child to complete*/
printf("I am the parent %d\n",pid);
wait(NULL);
printf("Child Complete\n");
}
return 0;
}
1. Write program codes for 3.21 a and...
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(“ | | ...
What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int x = 5; int y = 2; int z = 30; x = fork(); y = fork(); if (x != 0) printf("Type 1\n"); if (y != 0) printf("Type 2\n"); z = fork(); if (x > 0 || y > 0 || z > 0) printf("Type 3\n"); if (x == 0 && y == 0 && z != 0) printf("Type 4\n"); if (x...
With explanation Please.
#include #include <sys/types.h> <unistd.h> int main void ) fork fork fork execip ( "/bin/ls", return 0 /* Line A /* Line B/ /*Line C/ /. Line D ./ "ls", NULL); Answer the following: (a) Including the initial parent process, how many processes are created by the program? (b) Answer (a) assuming that lines C and D are interchanged in the program (c) Answer (a) assuming that lines B and D are interchanged (instead of C and D)...
Rewrite the program as a set of two programs that utilize a named pipe “ages” in the current folder for IPC and implement the same function as discussed above. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> int main(void) { int fd[2], nbytes; pid_t childpid; int users = 95; char mystring[80]; char readbuffer[80]; char digit1,digit2; digit1 = (char) users%10; digit2 = (char ) users/10; mystring[0] = digit1; mystring[1] = digit2;...
Combine two codes (code 1) to get names with(code 2) to get info: Code 1: #include<unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<dirent.h> #include<stdio.h> #include<stdlib.h> void do_ls(char []); int main(int argc,char *argv[]) { if(argc == 1) do_ls("."); else while(--argc){ printf("%s:\n",*++argv); do_ls(*argv); } } void do_ls(char dirname[]) { DIR *dir_ptr; struct dirent *direntp; if((dir_ptr = opendir(dirname)) == NULL) fprintf(stderr,"ls1:cannot open %s\n",dirname); else { while((direntp = readdir(dir_ptr)) != NULL) printf("%s\n",direntp->d_name); closedir(dir_ptr); } } ____________________________ code 2: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> void show_stat_info(char *,...
M ALL ELEG220 LABS jamalbaraka X Race Condition in operating syst X o Mail- Jamal A Baraka Outlook nments.dk X Lauk.edu.kw/pluginfile.php/214840/mod_resource/content/1/Assignment-1.pdf 1. Including the initial parent process, how many processes are created by the program shown in the following Figure? #include <stdio.h> #include <unistd.h> int nain) int i for (i 0; i< 4; i++ ) fork); return 0; Using the program shown in the following Figure, explain what the output will be at lines X and Y. 2. include ays/types.h...
modify the code for timer_test_02.c to allow the time delay between events to be pseudo- random exponential, with a mean time between arrivals of 0.1 second. Change the limit in the time_stamps() function from 5 time-stamps to 10, so that the mean run-time will be about 10*0.1 = 1.0 seconds. Once this is working, you should be able to generate 10 events with a pseudo-random exponential arrival process. The code is: #include <stdio.h> #include <stdint.h> #include <time.h> #include <unistd.h> #include...