Managing Processes
◾
145
4.5 MANAGING LINUX PROCESSES
By default, Linux runs processes and threads together by switching off between them. This
is known as concurrent processing in that processes (and threads) overlap in execution.
Because of the speed and power of modern processors, the user is typically unaware of the
time elapsing as the processor moves from one process to another and back. Literally, the
processor moves back to the first process in under a millisecond (thousandths of a second).
Concurrent processing of processes is known as multitasking
while concurrent processing
of threads is known as multithreading. Linux does both.
We mentioned the difference between processes and threads in Section 4.2, but let us
explore this again. A process is a stand-alone entity, it has its own code, data, and sta-
tus information. A thread, sometimes
called a lightweight process, shares its code and
data (or at least some data) with other threads. Threads are in essence portions of a pro-
cess. Threads will communicate with each other through shared data. For the processor
to switch between threads, it does not have to load new program code into memory as it is
already present. Switching between processes often requires additional overhead.
We should also define an application.
As users, we run programs like Firefox or
OpenOffice Writer. However, larger applications like these do not consist of single pro-
cesses. Instead, there are many different processes that might run in support of such soft-
ware. Some of these processes are services (parts of the operating system, covered later in
the textbook). Some of these are multiple processes that support each other. In other cases,
there may be a single process which spawns child processes or child threads.
Although
by default, Linux executes processes and threads using multitasking and mul-
tithreading, it does not mean that all processes run in this fashion. As a user, you can dic-
tate how processes run. The Linux command
batch
, for instance,
forces a process to run
in batch mode. A batch process is one that does not interact with the user. Therefore, any
batch process must be provided its input at the time the process executes. Output might be
sent to a file or to a terminal window. Batch processing in Linux defaults to executing only
if system load permits it. This occurs when CPU utilization drops below a pre-set amount,
usually 80%. Background processes that require I/O essentially are stopped so that they
do not take up CPU time.
In effect, if you are running entirely from the command line
(no GUI at all), and you are not running background processes, then you are running in a
single tasking mode.
Since the default is to run processes (and threads) concurrently, does the user have any
control over how these are run? That is, can the user dictate that
certain processes are more
important than others? The answer is yes, by specifying priorities for processes. Priorities
establish the amount of CPU time that processes are given as the CPU switches off between
them. The higher the priority, the more attention the CPU provides the given process.
A process’ priority is established by setting its
Do'stlaringiz bilan baham: