Answered step by step
Verified Expert Solution
Question
1 Approved Answer
what is the output and please explain the code how many processes and threads were created what are the contents of emilia.txt is line 28
what is the output and please explain the code how many processes and threads were created what are the contents of emilia.txt is line 28 important what is the purpose of dub2
1 void* rem (void *args) { 2 3 4} 5 void* ram (void *args) { 6 7 18 19 20 21 8} 9 int main(void) { 10 11 12 13 14 15 16 17 22 23 24 25 26 27 28 29 30 printf("Blue: %d ", *((int*) args)); exit(0); 31 32} printf("Pink: %d ", ((int*) args)[0]); return NULL; pid_t pid; pthread_t pthread; int status; //declaring vars int fd = open("emilia.txt", O_CREAT | O_TRUNC | O_WRONLY, 0666); int *subaru = (int*) calloc(1, sizeof(int)); printf("Original: %d ", *subaru); if(pid = fork()) { *subaru = 1337; pid = fork(); } if(!pid) { } else { pthread_create(&pthread, NULL, ram, (void*) subaru); for (int i = 0; i < 2; i++) waitpid (-1, &status, 0); pthread_create(&pthread, NULL, rem, (void *) subaru); } pthread_join(pthread, NULL); if(*subaru == 1337) dup2 (fd, fileno (stdout)); printf("All done! "); return 0;
Step by Step Solution
★★★★★
3.43 Rating (150 Votes )
There are 3 Steps involved in it
Step: 1
OUTPUT Original 0 Blue 0 All done Explanation This C program creates 3 processes and 2 threads The main process creates two child processes using the ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started