Question

I will provide, best rating. Please help me out understand how to solve part 2 of...

I will provide, best rating. Please help me out understand how to solve part 2 of this problem. I'm not sure how to make this work using ONLY the exec-family. No system() function call.

1. Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command: ps –l The process states are shown below the S column; processes with a state of Z are zombies. The process identifier (pid) of the child process is listed in the PID column, and that of the parent is listed in the PPID column. The easiest way to determine that the child process is indeed a zombie is to run the program that you have written in the background (using the &) and then run the command ps –l to determine whether the child is a zombie process. Because you do not want too many zombie processes existing in the system, you will need to remove the one that you have created. The easiest way to do that is to terminate the parent process using the kill command. For example, if the process id of the parent is 4884, you would enter kill -9 4884

2. Write another C program that does #1 automatically. That is, you do not have to enter the commands ps and kill manually. But your program has to: (a) create zombie processes by running your C program of #1, (b) Obtain the state of each process and find if there is any process that is zombie, (c) Show a list of processes with their states, (d) kill the parent of any process that is zombie, and (e) show the updated list of processes with their states.

Please help me understand how to create/come to a solution.

Thank you !

0 0
Add a comment Improve this question Transcribed image text
Answer #1
hello you just try this code for the questions you have asked.In this program parent process is identifying the zombie process and giving its states. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(void) { pid_t pid; int status; if ((pid = fork()) < 0) { perror("fork"); exit(1); } /* Child */ if (pid == 0) exit(0); /* Parent * Gives you time to observe the zombie using ps(1) ... */ sleep(100); /* ... and after that, parent wait(2)s its child's * exit status, and prints a relevant message. */ pid = wait(&status); if (WIFEXITED(status)) fprintf(stderr, "\n\t[%d]\tProcess %d exited with status %d.\n", (int) getpid(), pid, WEXITSTATUS(status)); return 0; }
Add a comment
Know the answer?
Add Answer to:
I will provide, best rating. Please help me out understand how to solve part 2 of...
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
  • Using either a UNIX or a Linux system, write a C program that forks a child...

    Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. Process states can be obtained from the command: ps -l The process states are shown below the S column; processes with a state of Z are zombies. The process identifier (pid) of the child process is listed in the PID column, and that of the parent is listed in the PPID column. Because you do not want...

  • C program To develop a C program to implement a process system call. PROBLEM You are...

    C program To develop a C program to implement a process system call. PROBLEM You are to use the Ubuntu operating system to write a C program that creates a process to determine the identification of the current user of your computer. I mean if joe is the login of the current user of your computer your solution should return joe. Your solution must also provide the pid of both the parent and the child processes. You may use the...

  • 1. Solve synchronization problems inherent in inter-process communication and multi-threaded applications.

    1. Process control system calls: The demonstration of fork, execve and wait system calls along with zombie and orphan states.a. Implement the C program in which main program accepts the integers to besorted. Main program uses the fork system call to create a new process called a child process. Parent process sorts the integers using merge sort and waits for child process using wait system call to sort the integers using quick sort. Also demonstrate zombie and orphan states.b. Implement...

  • Please I need help with this problem Write a c++ program that will accept the names...

    Please I need help with this problem Write a c++ program that will accept the names of 3 processes as command-line arguments. Each of these processes will run for as many seconds as (PID%10)*3+5 and terminate. After those 3 children terminated, the parent process will reschedule each child. When all children have been rescheduled 3 times, the parent will terminate. Each child must print out its process id every time it runs.

  • Part 2. System Programming and Process Management You are asked to develop basic system programmi...

    Can someone help me create this program for Linux. Part 2. System Programming and Process Management You are asked to develop basic system programming including process creation and termination on a Linux platform in this part of programming project. You are asked to create multiple children processes to work under one parent process. In theory, children processes can do their own work separately or cooperatively to accomplish a task. In this assignment, these children processes simply print out a "hello"...

  • Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork...

    Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...

  • Question 1 (a) Describe the five IP addressing classes. Provide an example for each of classes...

    Question 1 (a) Describe the five IP addressing classes. Provide an example for each of classes in binary and dotted-decimal representation. (b) Show the conversion of each of the addresses. (c) Describe the function of the subnet address for each of the classes and how does it work. [20 Marks] Question 2 (a) Define message switching, circuit switching and packet switching. Draw a diagram for each method to show the difference between them. (b) Identify the samples of network environment...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

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

  • CSIT 345 Lab 2 Process Programming Your lab requirement is to write program codes for 3.21 and sh...

    *Help Please with the code** CSIT 345 Lab 2 Process Programming Your lab requirement is to write program codes for 3.21 and shared memory program for producer and consumer as shown in the following. You can start with the code provided in the virtual machine in the virtual box you installed. The code can be found in /home/oscreader/osc9e-src/ch3 a. For 3.21, you can start with the newprocposix.c and modify the code to meet your requirement. Then type: gcc neypCOCROSİS.c to...

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