CS183 Lab 5: Process Management

Goal: In this lab, you will learn how to manage processes on a Linux/Unix System.

Details: Some ill-behaved processes, either intentional or not, could easily bring down a production system if they are not managed properly. For example, a careless programmer might repeatedly create processes, and within seconds, the system would become unresponsive and even crash eventually.

For the purpose of this lab, you will be using a program to simulate various scenarios to stress test a system. The program can be downloaded from here. Compile the program and name the executable proc.

Zombie Processes

Run './proc -n 10 -s 60 -z' with your account to create 10 zombie processes. Use ps and top commands to identify those zombies. Note that proc will try to disguise itself, so, do not look for the name. Instead, try to look at the status of the processes.

Runaway Processes

Run './proc -h' with your account to create a process that hogs the CPU. Use ps and top commands to identify the process. Write a Bash script that will be run by the crontab every minute to catch and kill any runaway process (excluding the root processes) that consumes CPU time for more than 2 minutes. Be sure to run './proc -h' multiple times and show that your script works.

Hint: It may be a little tricky to get the Bash script to work correctly. So, you may leave this section to the last. If this is the case, be sure to undo the next section, Revisit Runaway Processes, before coming back here.

Revisit Runaway Processes

PAM (Pluggable Authentication Modules) provides an easy mechanism to limit the CPU time usage of each process. Edit /etc/security/limits.conf as root and add a new line to setup a hard limit for the CPU time to 2 minutes for your user account. In order for the limit to work, all affected users have to logout and log back in after the changes have been made. Run './proc -h' again and run top to show the runaway process is killed when it goes beyond the limit.

Limit the number of processes

Run './proc -n 10000 -s 100' with your user account to create 10 thousands processes, each process will sleep for 100 seconds. Then try to login from another console, ie. press Alt-F2, and do 'ls -l' after login. You should notice the slowness of your system. If not, increase the number of option -n for the proc program and try again.

Now, edit /etc/security/limits.conf as root and add a new line to setup a hard limit for the maximum number of processes to 20 for your user account. Remember to log yourself out and login again. Run the same command again and show what happens. Additionally, run './proc -n 20' and see what happens. Explain why there are fewer processes (should be 18 in this case) allowed to be created by proc.

Limit the number of open files

Run './proc -f 2000 -s 100' with your user account. Count how many files can be created simultaneously in your current directory. Hint: Do not use your fingers to count :) proc will clean up all the files it created. However, if it does not for some reasons, you may remove them manually by running 'rm file_*.tmp'.

Now, edit /etc/security/limits.conf as root and add a new line to setup a hard limit for the maximum number of open files to 20 for your user account. Remember to log yourself out and login again. Run the same command again and show what happens. Additionally, run './proc -f 20' and see what happens. Explain why there are fewer open files (should be 17 in this case) allowed to be created by proc.

Questions

  1. What is a zombie process?
  2. What are runaway processes?
  3. Show and comment your Bash script that kills processes consuming the CPU for more than 2 minutes in the Runaway Processes section above?

Scoring


Notes & Tips: