Ubuntu 11.04 - Process management (2/6)

General Information
This is the result of personal research through community and official documentation about GNU/Linux and Ubuntu. References used are provided also. It will be presented in 6 posts as listed below:


Introduction
UBUNUT Linux11.04 is based on 2.6.38 Linux kernel (https://wiki.ubuntu.com/NattyNarwhal/ReleaseNotes). As far as the process management is concerned, UBUNTU Linux11.04 has preemptive kernel and supports Symmetric Multiprocessing (SMP).
There are two spaces that we identify in process circle. The kernel space and the user space. The process management takes place in the kernel space.
The scope of this paper is to present how the process management takes place in UBUNTU 11.04 GNU/Linux in both User Interfaces available, and how to admiister the system using the standard tools that come with the OS. Since the OS is developed under the GNU GPL (http://www.gnu.org/licenses/gpl.html), there are a lot more tools available , but they are outside the scope of this paper.
Before going through the presentation of the tools, a small introductional information is provided I norder to better ubderstand abbreviations and procedures to be discussed.
Basic aknowledgements
Components of the UBUNTU/Linux system
As every Linux system, UBUNTU is composed of three main parts of code.
  • The kernel
It is the heart of the OS. “It is responsible for mainting all the important abstractions of the operating system, including such things as virtual memory and processes” (Operating Systems Concepts, p. 807)
  • System libraries
They include sets of fucntions that do not need kernel priviledges in order applications to interact with the kernel.
  • System utilies
They include programs that perform individual management tasks, eg initialize, configure aspects of the system. In addition there are the so called deamons, that “may run permanently, handling such tasks as responding to incoming network connections, accepting logon requests from terminal and updating log files” (Operating Systems Concepts, p. 807).
Processes and threads.
Processes and threads are not that different for linux. Both fork() and exec() are used to create processes. Threads are created by the clone() system call. Clone() creates a child process allowing it to use shared information with the parent process by sets of flags that are passed to it. This how a thead is described in other Operating Systems. Exec() is the system call used to run new program whereas fork() is the system call to create a new process. In general it can be said that fork() is similar to clone() when no flags are passed to the new process. (Operating Systems Concepts, p. 815)
Process properties
Process poperties fall into three groups:
  1. Process identity
  • Process ID (PID)
It is the unique identifier of the process. It is used to specify the process to the OS. It does not change until the process termination.
  • Credentials
Also known as User ID (UID) and Group ID (GID). It determines the rights and privilegdes of the process to access system resources.
  • Personality
It can modify the semantics of certain system calls. It is used primarly by emulation libraries in order to request the combatible system call with certain varieties of UNIX.
  1. Process environment
It “is inherited from its aprent process and is composed of two null-terminated vectors; the argument vector and the environment vector (Operating System Concepts, p.813). The environment vector is a list of “NAME=VALUE” paris that associate named enviroment variables with arbitary textual values. eg. The LANG variable determines the language that is to be used to display system messages.
  1. Process Context
It represents the state of the process and it constantly changes. It inculdes the parts listed in the table 1 below.

Description
1
Scheduling Context
2
Accoutning
3
File table
4
File-sysstem context
5
Signal-handler table
6
Virtual memory context
Table 1. Parts of the Process context (Operating System Concepts, p.814)

Scheduling
UBUNTU Linux 11.04 have two seperate process-scheduling algorithms. “One is time-sharing for fair, preemptive scheduling among multiple processes; the other is designed fo real-time tasks.” (Operating System Concepts, p.815) “Real-time algorithms are also supported, for special time-critical applications that need precise control over the way in which runnable processes are selected for execution.” (http://manpages.ubuntu.com/manpages/natty/man2/sched_setscheduler.2.html)
The time sharing algorithms are three.
  • SCHED_OTHER
  • SCHED_BATCH
  • SCHED_IDLE 
For the time sharing algorithms, the standard Round-Robin method is used. It is a First-Comes-First-Served (FCFS) method, but also assingning a time quanta for each process, creating a loop ending with the init() system call, which is the parent of all processes. (http://manpages.ubuntu.com/manpages/natty/man8/init.8.html)
Two seperate priority ranges are used. A real time range from 0-99 and a nice value ranging from 100 to 140. In this scheme the numerically lower processes have higher priority. When a task is runnable, it enters a runqueue, mainted by the kernel. The runqueue includes two arrays. The active list, which contains the processes to be executed, and the expired list, which contains the tasks that have expired. If the time quanta does not allow the task to be completed, then it is considerd as expired and it goes back to the expired array list of the runqueue. When the acitve array of the active list = 0 then the expired list becomes the active one and vice versa. The runqueue is processor indepented.
The nice priority value is determined by how much time the task has been sleeping. It is dynamically changed and the scheduler infavors interactive tasks, which are tasks that have longer sleep times. The nice priority value is recalculated when the task enters the expired list.
The real time algorithms are the FCFS and the Round-Robin, which was described above, with the addition of a priority to the one of its scheduling class. When two processes have the same class, the one waiting in queue the lognest has higher priority. For processesof different class the one with the hight class has the higher priority.
Kernel synchronization
Tasks may try to access the same internal data structures. Since UBUNTU Linux are preemptive, if another task with higher priority is ready to use CPU time, the running task will be preempted even if running in kernel.
In order to lock the kernel, UBUNTU provides spinlocks and semaphores.For Symmetric Multiprocessing machines, spinslocks are the fundamental mechanism. This cannot happen in single processor machines since there is only one CPU time and locking for short periods, which is what spinslocks do, would have high impact to the system performance. Instead of spinlocks, in single processor machines, the preemptive ability is enabled and disabled instead.
The most important aspect in preemptive mechanism is what happens with interrups. IN UBUNTU the interrupts are prioritized and seperated into two parts. The top-half one and the bottom-half one. An interrupt form the first class can interrupt one form the second class, but cannot interrupt another of the same class.
A simplified example overviewing what has been discussed so far is presented in figure 1 below.
Administration utilities found in the GUI (UNITY)
The graphical utility can be found in “system settings” → “system monitor”. The second tab called “resources” shows the running processes in queue. 
The monitor informs us about:The process name
  • The status of the proces
  • The CPU % usage
  • The Nice priority value
  • The PID
  • The memory usage
By right clicking in a entry, a menu appears, allowing us:
  • to stop a proces
  • to continue a stopped proces
  • to end a process (asking to end)
  • to kill a proces (forcing to terminate)
  • to change priority
  • the memory maps (VM start and end values)
  • and to show the linked files
Administration utilities used from the command-line
There are several commands that be used to monitor and manage the running processes of the system. Since the terminal is addressed to advanced users everything cannot be presented in this paper.
In order to interact with a task in terminal, we need to know either the PID or the name of the task. The table below summarises the most useful commands for process management through the terminal. The description of each command as well as the available arguments can be viewed by typing (command) --help, or man (the name of the command)

Name
Description
1
ps
With the appropriate arguments it can show all the running processes, the process runnning from a user
2
pstree
Shows the runnning processes in a tree scheme
3
kill
Kill a process by PID
4
killall
Kill a process by name
5
nice
Sets the priority of new processe
6
renice
Changes the priority of a currently running process
7
skill
Reports process status
However, I believe that the most usefull command for the process management throught the terminal is the command top. It is a real time non graphical “System Monitor”. 
Althought the number of the taks running is bigger and because it changes dynamically, the best proposed use of it is to use the results of the top command exporting them in home folder in a text file, like this
top >> ~/top.txt, which will overwrite a text file in the home folder with the name top.
It will provide with all the necessary information to manipulate the running tasks in the system. The “h” key shows the help menu na the “q” is used to exit the top command.
Conclusion
Ubuntu Linux 11.04 is cooperative or preemptive OS. There is practically no difference between processes and threads. The process management takes place in the kernel space and it works in SMP machines . Finally it provides us with tools to manipulate the processes running in both the graphical and the terminal interface.
References
  1. http://www.gnu.org/licenses/gpl.html as found on May 2nd 2011
  2. Operating System Concepts, 8th edition, International stucent version, Abraham Silberschatz, Peter B. Galvin, Greg Gange, Wiley 2010

Comments

  1. Good post but the grammar makes me cringe.

    ReplyDelete
  2. Good work :)

    ReplyDelete

Post a Comment

Popular posts from this blog

Ubuntu 11.04 - Memory management (3/6)

Ubuntu 11.04 - General Overview (1/6)