Real-Time Processes


Many types of applications require deterministic and predictable execution. These include factory automation programs; programs that run telephone switches; and programs that monitor medical information, such as heartbeats. Current workstations can play digitally stored music or voice recordings as well as movies. Acceptable playback of these materials requires that pauses not be introduced by the system. Early releases of UNIX ran all processes on a time-sharing basis, allocating resources according to an algorithm that allowed different processes to take turns using system resources. This made it impossible to guarantee that any process would run at a specific time within a specific time interval.

UNIX systems today have support for real-time processes. The real-time enhancements can be used to support many kinds of applications requiring deterministic and predictable processing, such as running processes on dedicated processors used for monitoring devices. However, some real-time applications, such as robotics, that depend on deterministic processing with extremely short scheduling intervals are still difficult to implement because of limitations involving how the UNIX system kernel and input/output work. Some of these limitations will be eliminated in future releases of UNIX.

Priority Classes of Processes

UNIX supports five configurable classes of processes with respect to scheduling: the real-time class (RT), the fixed-priority class (FX), the time-sharing class (TS), the fair-share class (FS), and the interactive class (IA). Each class has its own scheduling policy, but a real-time process has priority over every time-sharing or interactive process. The interactive class is basically the same as the time-sharing class, with an additional priority given to it as an active window task.

Besides these classes, there is a sixth class, the system class (SYS), which consists of special system processes needed for the operation of the system. The system class is reserved for use by the kernel. You cannot change the scheduling parameters for these processes. Also, you cannot change the class of any other process to the system class. Processes in the system class have priority over all other processes.

Real-Time Priority Values

A process in the real-time class has a real-time priority value (rtpi value) between 0 and x. The parameter x, the largest allowable value, can be set for a system. The process with the highest priority is the real-time process with the highest rtpi value. This process will run before every other process on the system (except system class processes).

Time-Sharing User Priority Values

Each process in the time-sharing class has a time-sharing user priority (tsupri) value between x and x, where the parameter x can be set for your system. Increasing the tsupri value of a process raises its scheduling priority However, unlike a real-time process, a time-sharing process is not guaranteed to run prior to time-sharing processes with lower tsupri values, because the tsupri value is only one factor used by the UNIX System to schedule the execution of processes.

Setting the Priority of a Process

To use the priocntl command to change the scheduling parameters of a process to real-time, you must be the superuser or you must be running a shell that has real-time priority Also, to change the scheduling parameters of a process to any class, your real or effective ID must match the real or effective ID of that process, or you must be the superuser.

Assuming you meet these requirements, you can set the scheduling class and priority of a process by using the priocntl command with the -s (Set) option. For example,

 # priocntl -s -c RT -p 2 -i pid 117

sets the class of the process with process ID 117 as real-time and assigns it a real-time priority value of 2. The command

 # priocntl -s -c RT -i ppid 2322

sets the class of all processes with parent process ID 2322 as real-time and assigns these processes the real-time priority value of 0, since the default value of rtpi for a real-time process is 0.

The general form of the priocntl command with the -s option is

 # priocntl -s [-c class] [class-specific options] [-i idtype] [idlist]

The minimum requirement for changing the scheduling parameters of a process is that your real or effective ID must match the real or effective ID of that process, or you must be the superuser.

Executing a Process with a Priority Class

You can use the priocntl command with the -e (execute) option to execute a command with a specified class and priority. For instance, to run a shell, using the sh command, as a real-time process with the real-time priority value of 2, use the command line

 # priocntl -e -c RT -p 2 sh

(A system administrator may want to run a shell with a real-time priority if the system is heavily loaded and some administrative tasks need to be carried out rapidly)

The general form of the priocntl command with the -e option is

 # priocntl -e [-c class] [class-specific options] [-i idtype] [idlist]

Time Quanta for Real-Time Processes

The priocntl command can also be used to control the time quantum, tqntm, allotted to a real-time process. The time quantum specifies the maximum time that the CPU will be allocated to a process, assuming the process does not enter a wait state. Processes may be preempted before receiving their full time quantum if another process is assigned a higher real-time priority value.

You can set the time quantum for a process by using the -t (tqntm) option to prioctnl. The default resolution for time quanta is in milliseconds. For instance,

 # priocntl -s -c RT -p 20 -t 100 -i pid 1821

sets the class of the process with PID 1821 to be real-time, with rtpi 30 and a time quantum of 100 milliseconds, which is 1/10 of a second.

You can also assign a time quantum when you execute a command. For instance,

 # priocntl -e -c RT -p 2 -t 100 sh

executes a shell with a real-time priority value of 2 and a time quantum of 100 milliseconds.

Displaying the Priority Classes of Processes

You can use the priocntl command with the -d (display) option to display the scheduling parameters of a set of processes. You can specify the set of processes for which you want scheduling parameters. For instance, you can display the scheduling parameters of all existing processes using the command line shown here:

 # priocntl -d -i all TIME SHARING PROCESSES:     PID    TSUPRILIM     TSUPRI       1        0            0     306        0            0     115        0            0   15291        1            1    1677        8            4      157        0            0   15306        0            0    1725        0           −8   15307        0            0    1668        0            0    1698       10           10   15305        0            0    6154       −4           −4   15310        0            0 REAL TIME PROCESSES :     PID    RTPRI        TQNTM    1888      15         1000   15317       2          100   15313       2          100   15315       2          100    1003       0         1000     918      50          1000 +

On Solaris 10 UNIX, you can use the ps command to do this:

 # ps -ecl

will display a list of all the running processes, including the class they are running under (shown as SYS), as well as the priority of the process (shown as PRI).

You can also display scheduling parameters for only one class of processes. For instance, you can use the command line

 # priocntl -d -i class TS

to display scheduling parameters for all existing time-sharing processes.

You can further restrict the processes for which you display scheduling parameters by using the -i option. For instance, the command

 # priocntl -d -i pid 912 3032 3037

displays scheduling parameters of the processes with process IDs 912, 3032, and 3037. The command

 # priocntl -d -i ppid 2239

displays the scheduling parameters of all processes whose parent process ID is 2239.

The general form of the priocntl command that you use to display information is

 # priocntl -d [-i idtype] [idlist]

Displaying Priority Classes and Limits

You can determine which priority classes are configured on a system using the priocntl command with the 1 option, as in this Solaris 10 example:

 # priocntl −1 CONFIGURED CLASSES ================== SYS (System Class) TS (Time Sharing)       Configured TS User Priority Range: −60 through 60 IA (Interactive)       Configured IA User Priority Range: −60 through 60 FX (Fixed priority)        Configured User Priority Range: 0 through 60

The output in this example shows that there are three priority classes defined on this system: the System Class, the Time Sharing Class, and the Real Time Class. The allowable range of tsupri values is 20 to 20, and the maximum allowable rtpi value is 59.

The /proc File System

The /proc file system is a very useful directory structure for the system administrator. It is a virtual file system-residing in memory-that is created each time the system is booted. The /proc directory structure provides an easy method of accessing information about the state of the kernel, the attributes of the machine, the states of individual processes, and more. As an example the ps and cat commands use the contents of /proc to get process information.

There are a number of directories in the /proc file system. Some of them consist of numbers only These are the directories associated with process IDs (PIDs) of various processes running on the system. There are also directories consisting of nonnumerical names that deal with the UNIX kernel features, such as the CPU, devices, memory, interrupts, networking, and loaded modules.

An experienced system administrator can use one of the directories within the /proc file system, the /sys directory, to perform kernel tuning on the system. Since this is such a powerful capability, it’s best to understand what effect manipulating the contents of /sys will have before attempting to do so on a live system.




UNIX. The Complete Reference
UNIX: The Complete Reference, Second Edition (Complete Reference Series)
ISBN: 0072263369
EAN: 2147483647
Year: 2006
Pages: 316

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net