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

Assignment Write a program in C language that should be able to run inLinux envi

ID: 3610475 • Letter: A

Question

Assignment

Write a program in C language that should be able to run inLinux environment. This program should be able to perform followingtasks. Use necessary system calls to complete this program.

·         Aprocess creates a child process.

·         Displaythe process id of both parent and child processes.

·         Createa pipe and through that pipe, child sends a message“Assalam O Alaikum” to its parentprocess. And parent process displays that message on thescreen.

Note:

Develop this program in Linux or use any other softwareapplication (like Cygwin) that supports all the APIs (system calls)necessary to develop this program.

Explanation / Answer

//Hope this will help you. //Don't forget to rate it. #include #include #include #include #include #include int main(int argc, char *argv[]) {     int pfd[2];     pid_t cpid;     char buf;     if (pipe(pfd) == -1) { perror("pipe");exit(EXIT_FAILURE); }     cpid = fork();     if (cpid == -1) { perror("fork");exit(EXIT_FAILURE); }     if (cpid == 0) {         close(pfd[1]);         while (read(pfd[0],&buf, 1) > 0)            write(STDOUT_FILENO, &buf, 1);         write(STDOUT_FILENO," ", 1);         close(pfd[0]);         _exit(EXIT_SUCCESS);     } else {        printf(" child pid =%d",cpid);        printf(" parent pid =%d",getpid());         close(pfd[0]);         write(pfd[1],"Assalam OAlaikum", strlen("Assalam O Alaikum"));         close(pfd[1]);         wait(NULL);         exit(EXIT_SUCCESS);     } }
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