Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that you have three programs that are suppose to print a house diagram i

ID: 3740390 • Letter: S

Question

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

    printf(“           ^^^^^^^^^^^            ^^^^^^^^^^^            ”);

    printf(“^^^^^^^^^^^                                  ^^^^^^^^^^^ ”);

    printf(“     |                                            |      ”);

    printf(“     |                                            |      ”);

    exit(1);

}

(i) prog2.c

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

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

int main()

{

   

    printf(“     |                                             |     ”);

    printf(“     |                                             |     ”);

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

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

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

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

    exit(1);

}

(i) prog3.c

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

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

int main()

{

      

   

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

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

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

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

    printf(“     |                                             |     ”);

    printf(“     |                                             |      ”);

    printf(“     ______________________________________________      ”);                                          |     ");

    exit(1);

}

1. Write a 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!

2. Write a c program (name it as house2.c) that draws a 2-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!

1. Write a c progran (nane it as house1.c) that draws a 1-story house diagran correctly. Your pr ogram should use the following system calls: . fork) any variant of the exec class system calls You have to remember Pnshen rbogn sheu d be tiar nrouats itteecution after progt 1s prog1.c, prog2.c and prog3.c should be executed in a specific correctly Your program should use the following systen calls fork( any variant of the exec class system calls You have to romember prog1.c, prog2.c and prog3.c should be executed in a speciric order finished and prog3 should be initiated after prog? is fini shed

Explanation / Answer

First compile prog1.c prog2.c pro3.c into its output file.

gcc prog1.c -o a

gcc prog2.c -o b

gcc prog3.c -o c

compile the main file as ->gcc main.c -o main

keep all object file in same place

then run main-> ./main

Ans 1)

#include<stdio.h>

#include<sys/types.h>

int main()

{

pid_t p;

p=fork();

if(p==0)

execl("./a","/a",NULL); //first prog

else

waitpid(p); //wait for prog1 to finish

p=fork();

if(p==0)

execl("./b","/b",NULL); //second prog

else

{

waitpid(p); //wait for prog2 to finish

p=fork();

if(p==0)

execl("./c","/c",NULL);

else

waitpid(p);

}

return 0;

}

Ans 2)

for making 2 storey building prog1->prog2->prog3->prog2->prog3

#include<stdio.h>

#include<sys/types.h>

int main()

{

pid_t p;

p=fork();

if(p==0)

execl("./a","/a",NULL); //first prog

else

waitpid(p); //wait for prog1 to finish

p=fork();

if(p==0)

execl("./b","/b",NULL); //second prog

else

{

waitpid(p); //wait for prog2 to finish

p=fork();

if(p==0)

execl("./c","/c",NULL);

else

{

waitpid(p);

p=fork();

if(p==0)

execl("./b","/b",NULL);

else

{

waitpid(p);

p=fork();

if(p==0)

execl("./c","/c",NULL);

else

waitpid(p);

}

}

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote