When Users Go Berserk ®
AND
a B.O.F.H. tool
|
Hosted by
|
Porting
|
This page contains information on how to port
the auto nice daemon to other operating systems.
Back to main page
|
|
AND
Porting Notes
Porting AND to other Unices isn't really difficult, but requires
some intimate knowledge of the target system's process management.
Actually you just have to write two functions to interate through
the list of processes, which return pointer to the following data
structure (only the part to be filled by the OS-specific code
is shown):
struct and_procent {
int pid; /* process ID */
int ppid; /* parent process ID */
int uid; /* user ID */
int gid; /* group ID */
int nice; /* current nice level */
unsigned utime; /* CPU time used by program */
char command [1024]; /* command (no cmdline options) */
};
These two routines, let's call them newOS_getfirst() and
newOS_getnext(), return a pointer to the first, and any
further structures mentioned above, or NULL if all processes
have been processed. The Linux version is just about 100 lines
of code.
On Linux, linux_getfirst() opens the /proc
directory and then calls linux_getnext(), which searches
the next available entry representing a process, reads the
corresponding /proc/<pid>/stat file and fills
the and_procent structure. If no more process entries
are avaliable, NULL is returned (don't forget to rewinddir() /proc).
On other SysV-ish Unices, the strategy will probably be similar,
but the /proc filesystem and /proc/<pid>/stat
file format will probably be different, or the information is
stored in /proc/<pid> directly (e.g. Digital UNIX,
IRIX and Solaris; thanks to Dan Stromberg/UCI for pointing out that
the Digital UNIX source also works for IRIX and Solaris!)
Copy and-linux.c to and-newOS.c, replace
linux_getfirst() and linux_getnext() with
newOS_getfirst() and newOS_getnext(), add
an entry in the Makefile, test it, and send me the changes so I can
incorporate it into the official AND release.
The Digital UNIX port was done in below one hour. The OpenBSD
port was done in two evenings - OpenBSD doesn't use a /proc
filesystem but the KVM interface, which is considerably different.
|