Question

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(“     |                                             |     \n”);

    printf(“     |                                             |     \n”);

    printf(“     |     ^^^^^^^^^^^            ^^^^^^^^^^^      |     \n”);

    printf(“     |     ^         ^            ^         ^      |     \n”);

    printf(“     |     ^         ^            ^         ^      |     \n”);

    printf(“     |     ^         ^            ^         ^      |     \n”);

    exit(1);

}

(i) prog3.c

#include <stdio.h>      /* Input/Output */

#include <stdlib.h>     /* General Utilities */

int main()

{

    printf(“     |     ^          ^           ^         ^      |     \n”);

    printf(“     |     ^          ^           ^         ^      |     \n”);

    printf(“     |     ^          ^           ^         ^      |     \n”);

    printf(“     |     ^^^^^^^^^^^            ^^^^^^^^^^^      |     \n”);

    printf(“     |                                             |     \n”);

    printf(“     |                                             |      \n”);

    printf(“     ______________________________________________      \n”);                                                                                            |      \n");

    exit(1);

}

Fill out the following c program (name it as house1.c) that draws a 1-story house diagram correctly. Your program should use the following system calls:

  • fork()
  • any variant of the exec class system calls
  • waitpid()

You have to remember prog1.c, prog2.c and prog3.c should be executed in a specific order in a synchronized manner, i.e., prog2 initiates its execution after prog1 is finished and prog3 should be initiated after prog2 is finished!

Note1: prog1, prog2, and prog3 should be executed by children processes. Parent process should not execute any of these.

Note2: Exception handling should be done when any of the system calls fails such as fork(), execl(), etc.

#include<sys/types.h>

#include<sys/wait.h>

#include<unistd.h>

#include<stdio.h>

#include<stdlib.h>

int main()

{

    pid_t pid1;

    pid_t pid2;

    int status;

    pid1 = -1;

    pid2 = -1;

    pid1 = fork();

    pid2 = fork();

    if (pid1 == 0 && pid2 == 0)

    {

       // Fill out this part!

    }

    if ( pid1 == 0 && pid2 > 0)

    {

       // Fill out this part!

    }

    if ( pid1 > 0 && pid2 ==0)

    {

         // Fill out this part!

    }

    if ( pid1 >0 && pid2 > 0)

    {

         // Fill out this part!

    }

}

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Suppose that you have three programs that are suppose to print a house diagram in a...
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
  • Rewrite the program as a set of two programs that utilize a named pipe “ages” in...

    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;...

  • What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main()...

    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...

  • plz help me

    #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.

  • Modify the programs so that each program can both receive and send messages alternatively. Note that when you run the two programs, you should run them in two different windows ( terminals). Y...

    Modify the programs so that each program can both receive and send messages alternatively. Note that when you run the two programs, you should run them in two different windows ( terminals). You should be able to send messages from one to the other and terminate them by entering "end" //msgl.cpp / Here's the receiver program. / #include #include #include #1nclude #include <stdlib.h> <stdio.h> <string.h> <errno.h> <unistd.h> #include <sys/types.h> #include <sys/ipc.h> Winclude <sys/msg.h> struct my msg st f long int...

  • My question is listed the below please any help this assignment ; There is a skeleton...

    My question is listed the below please any help this assignment ; There is a skeleton code:  copy_file_01.c #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { char ch ; FILE *source , *target;    if(argc != 3){ printf ("Usage: copy file1 file2"); exit(EXIT_FAILURE); } source = fopen(argv[1], "r"); if (source == NULL) { printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } target = fopen(argv[2], "w"); if (target == NULL) { fclose(source); printf("Press any key to exit...\n"); exit(EXIT_FAILURE); } while ((ch...

  • Hello, how can i compile this C code using option -std=c99 or -std=gnu99 #include <stdio.h> #include...

    Hello, how can i compile this C code using option -std=c99 or -std=gnu99 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> static char* args[512]; pid_t pid; int command_pipe[2]; static void waiting(int n); static int command(int input, int first, int last) { int fd[2]; int flag=0; pipe( fd );   pid = fork(); if (pid == 0) { for(int i=0;args[i]!=0;i++) { if(args[i][0]=='>') { fd[1]=open(args[i+1], O_CREAT|O_TRUNC|O_WRONLY, 0644); flag=1; } if(args[i]=='>>' ) { fd[1]=open(args[i+1],...

  • I need help fixing this code in C. It keeps giving me an error saying error:...

    I need help fixing this code in C. It keeps giving me an error saying error: ‘O_RDWD’ undeclared (first use in this function) if ((fd = open(fifo, O_RDWD)) < 0) note: each undeclared identifier is reported only once for each function it appears in. Please fix so it compiles properly. //************************************************************************************************************************************************** #include <fcntl.h> #include <stdio.h> #include <errno.h> #include<stdlib.h> #include <string.h> #include<unistd.h> #include <sys/stat.h> #include <sys/types.h> #define MSGSIZE 63 char *fifo = "fifo"; int main(int argc, char **argv){    int fd;...

  • Run the code in Linux and provide the screenshot of the output and input #include <signal.h>...

    Run the code in Linux and provide the screenshot of the output and input #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/types.h> #include <sys/socket.h> static void cleanup(); static void docleanup(int signum); static const char *SERVER_ADDR = "127.0.0.1"; static const int SERVER_PORT = 61234; static int cfd = -1; int main(int argc, char *argv[]) { struct sockaddr_in saddr; char buf[128]; int bufsize = 128, bytesread; struct sigaction sigact; printf("client starts running ...\n"); atexit(cleanup); sigact.sa_handler =...

  • I have the following code....from the previous lab....the above needs to be added to what is...

    I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing)    pid_t pid;    int j;    //printf("Welcome to Project Three\n”);    // For loop*/    for (j = 1; j...

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