Rewrite Program Step 1 Two Threads Instead Two Processes Q43893436
Rewrite the program in Step 1. with two threads instead of twoprocesses
#include <stdio.h> /* printf, stderr */ #include <sys/types.h> /* pid_t */ #include <unistd.h> /* fork */ #include <stdlib.h> /* atoi */ #include <errno.h> /* errno */ /* main function with command-line arguments to pass */ int main(int argc, char *argv[]) { pidut pid; int i, n = atoi(argv[1]); // n microseconds to input from keyboard for delay printf(“n Before forking.n”); pid = fork ; if (pid == -1) { fprintf(stderr, “can’t fork, error %dn”, errno); if (pid) { // Parent process for (i=0; i<100; i++) { printf(“ttt Parent Process %d n”, i); usleep(n); else{ // Child process for (i=0; i<100; i++) { printf(“Child process %dn”, i); usleep(n); return 0; Show transcribed image text #include /* printf, stderr */ #include /* pid_t */ #include /* fork */ #include /* atoi */ #include /* errno */ /* main function with command-line arguments to pass */ int main(int argc, char *argv[]) { pidut pid; int i, n = atoi(argv[1]); // n microseconds to input from keyboard for delay printf(“n Before forking.n”); pid = fork ; if (pid == -1) { fprintf(stderr, “can’t fork, error %dn”, errno); if (pid) { // Parent process for (i=0; i
Expert Answer
Answer to Rewrite the program in Step 1. with two threads instead of two processes…
OR