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 use linux or unix to complete Diff command The diff command displays differences between two...
please use linux or unix to complete Diff command The diff command displays differences between two files on a line-by-line basis. It displays the differences as instructions that you can use to edit one of the files ( using the vi editor) to make it the same as the other. When you use diff, it produces a series of lines containing Append (a), Delete (d), and Change (c) instructions. Each of these lines is followed by the lines from the...
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 write simple python code Write a program to replicate the behavior of UNIX utility “tail”....
please write simple python code Write a program to replicate the behavior of UNIX utility “tail”. It takes one or more files and displays requested number of lines from the ending. If number is not specified, then it print 10 lines by default.
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
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
Please execute the appropriate Unix command to perform the action described. 1 - Put your login...
Please execute the appropriate Unix command to perform the action described. 1 - Put your login name in the file session03_hw. 2 - Put the date in mm/dd/yy format in the file session03_hw. 3 - Put the abbreviated weekday name in the file session03_hw. 4 - Put the time in hh:mm format in the file session03_hw. 5 - Use the command for a short listing with the option to list entries by columns. List files that start with mno and...
Unix: Compare a sure kill with a regular kill command. When should you use a sure...
Unix: Compare a sure kill with a regular kill command. When should you use a sure kill?
**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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT