Unix Process Control
Strategies for Unix process control offer another multiple-choice situation. Luckily, these choices aren’t nearly as complex to introduce as those offered by NT. When we speak of process control under Unix, we’re referring to three operations:
Enumerating the list of running processes on a machine
Changing their priority or process group
Terminating the processes
For the final two of these operations, there are Perl functions to do
the job: setpriority( ), setpgrp( ), and kill( ).
The first one offers us a few options.
To list running processes, you can:
Call an external program like ps
Take a crack at deciphering
/dev/kmemLook through the
/procfilesystemUse the
Proc::ProcessTablemodule
Let’s discuss each of these approaches. For the impatient
reader, I’ll reveal right now that
Proc::ProcessTable is my preferred technique, and
you might just skip directly to the discussion of that module. But I
recommend reading about the other techniques anyway, since they may
come in handy in the future.
Calling an External Program
Common to all modern Unix variants is a program called ps, used to list running processes. However, ps is found different places in the filesystem on different Unix variants and the command-line switches it takes are also not consistent across variants. Therein lies one problem with this option: it lacks portability.
An even more annoying problem is the difficulty in parsing the output (which also varies from variant to variant). Here’s a snippet ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access