Question

In: Computer Science

unix question please write a program and then show how to use top command that shows...

unix question

please write a program and then show how to use top command that shows the zombie process, give

snapshot of top command that shows the zombie process

  1. Write a very simple program that will show the possibility of having zombie processes. Write a program named zombie.c

The main process will create a child.

The child prints something like: “I am the child with pid ….. and my parent has ppid ….” Next, the child will sleep for 1 second.

Child exits.

The parent will print: I am the parent and my id is… Next, the parent sleeps for 30 seconds.

Since the child ends first, and the parent didn’t do wait( ), the child will be for a while in the zombie state. Run the parent in the background, so you can use the top command and identify the zombie, before the parent terminates.

Note: even if the parent terminates, the child is still a zombie. However the the init process reaps the zombies frequently.

Solutions

Expert Solution

Zombie.c

#include <stdlib.h>

#include <stdio.h>

#include<conio.h>

#include <unistd.h>

int main()

{

// fork() creates child process identical to parent

int pid = fork();

// if pid is greater than 0 than it is parent process

// if pid is 0 then it is child process

// if pid is -ve , it means fork() failed to create child process

if(pid<0)

{

//exit(1);

printf("failed to fork\n");

return -1;

}

//Parent Process

if(pid ==0)

{

sleep(1);

printf("I am the child process with pid %d and my parent has ppid %d\n ",getpid(),getppid());

exit(1);

}

else

{

printf("\nI am the parent and my id %d ",getpid());

sleep(30);

exit(0);

}

return 0;

}

#include <stdlib.h>

#include <stdio.h>

#include <unistd.h>

#include <string.h>

int main () {

system("./Assignment2a &");

system("ps -l");

sleep(3);

system("kill -9 $(ps -l|grep -w Z|tr -s ' '|cut -d ' ' -f 5)");

sleep(7);

printf("\n\nupdated list of processes with their states\n\n");

system("ps -l");

return(0);

}


Related Solutions

please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
assume a program in unix that have a multiple system calls how to show the list...
assume a program in unix that have a multiple system calls how to show the list of system calls used in the program?
Please use RStudio to answer the question and give the R command: please load data use...
Please use RStudio to answer the question and give the R command: please load data use data: library(MASS) data(cats) Use the “cats” data set to test for the variance of the body weight in male and female cats
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command that would find all lines that have an email address and place a label email = before the line in the file longfile output will multiple lines similar to this one : using a good awk command the output would be something like this email = From: "Linder, Jann/WDC" <[email protected]> email = To: Mr Arlington Hewes <[email protected]> email = > From: Mr Arlington Hewes...
Please use Phyton to write a program: Write a program that calculates and displays the total...
Please use Phyton to write a program: Write a program that calculates and displays the total bill at a restaurant for a couple that is dining. The program should collect from the couple, cost of each meal, and the percentage of the final cost that they would like to tip. The sales tax in the state where the restaurant exists is 7.5%. Display to the user, line by line: Total Cost of Both Meals Sales Tax in dollars Tip in...
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and...
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and then copy and paste the output page here (or in some cases the screenshot of the data view that shows the output). Can I Know also what is the sample file (in SPSS) that we work on? Question : (In this problem first find the probability by using SPSS and then calculate the number of trees manually by using the probabilities.) A certain variety...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
Code in C# please. Write a program that will use the greedy algorithm. This program will...
Code in C# please. Write a program that will use the greedy algorithm. This program will ask a user to enter the cost of an item. This program will ask the user to enter the amount the user is paying. This program will return the change after subtracting the item cost by the amount paid. Using the greedy algorithm, the code should check for the type of bill. Example: Cost of item is $15.50 User pays a $20 bill $20...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 1b) Write a C program that reads in a string from the keyboard. Use scanf with the conversion code %s. Recall that the 2nd arg in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT