Technical article 105690

"ps -n" command to identify booted kernel doesn't work on SCO OpenServer 5.

OpenServer 5.0.0OpenServer 5.0.2OpenServer 5.0.4OpenServer 5.0.5

Written · Last revised

Problem

In versions of SCO OpenServer operating systems prior to Release
5.0.0, I could use the "-n" option to the ps(C) command to
determine the booted kernel, or to run ps after relinking but
before rebooting. For instance, if I relink the kernel, by
default the current /unix gets moved to /unix.old, and a new
/unix gets created.  Since the new /unix does not match the
booted kernel in memory, this message:
ps: /unix: not the booted system
appears when the ps command is run.  However, in SCO OpenServer
Release 5, the -n option does not seem to work.  On an OpenServer
5.0.0, 5.0.2, or 5.0.5 system, if I enter the command:
ps -n /unix.old
before relinking, or the command:
ps -n /unix
after relinking but before rebooting, the ps command works in
both cases.  The same commands on an OpenServer Release 5.0.4
system result in the error:
ps: ERROR: Illegal option -- n

Why is this so, and what alternative do I have to easily identify the booted kernel?

Cause

The ps command in OpenServer 5 was changed to resolve the problem
of the command ceasing to function if the kernel was relinked but
not rebooted right away.  Thus the ps command in OpenServer 5
works whether or not /unix is the booted kernel.  This makes the
ps command more robust, but makes it impossible to determine
the name of the booted kernel with ps.

Solution

For OpenServer 5.0.4, this problem is fixed with Release Supplement
504C (RS504C), which gives it the same behavior as in SCO OpenServer
Release 5.0.0, 5.0.2, and 5.0.5.  Please read on for further
explanation of the behavior of this option in current releases
and what to do as a workaround.

First, consider the specific differences between the versions of ps in SCO OpenServer products, and then consider alternatives for determining the name of the booted kernel.

- SCO OpenServer Release 5.0.0 and 5.0.2
In these releases, the ps utility uses the tab(HW) (table) driver
to access the process table.  The associated device files are
/dev/table/proc and /dev/table/eproc.  If for some reason, these
devices cannot be successfully used, the ps utility uses the
/dev/kmem device, referencing the name and address information
in /unix in order to search /dev/kmem for the process table and
other data.  The -n option has no effect; only replacing the
current file /unix with another file of the same name will affect
the behavior of ps.  Since this is exactly what happens when the
kernel is relinked, if the ps command is run after a relink but
before a reboot, _and_ the /dev/table devices are inaccessible,
the error:
ps: /unix: not the booted system
will be displayed at this point.
- SCO OpenServer Release 5.0.4 and 5.0.5
In these releases, the ps utility only uses the devices
/dev/table/proc and /dev/table/eproc to access the process
table information.  If these devices are inaccessible, the
ps command will generate an error.  For instance, if
/dev/table/proc does not exist, the error:
ps: Cannot open /dev/table/proc for reading:
    No such file or directory (error 2)
will be displayed.  In addition, as mentioned above, the -n option
is not recognized by ps in OpenServer 5.0.4 until after Release
Supplement 504C (RS504C) is applied.

- Method to obtain name of booted kernel in SCO OpenServer 5

Since the -n option has no effect in OpenServer 5, you can do one of the following things in order to identify the booted kernel name:

1. use the kernel(ADM) command 2. devise your own method

Both methods will assume that the booted kernel is one of the default kernel files that are placed in the /stand or / directories; besides the file unix itself, all of these files are of the form unix*.

1. Use the kernel(ADM) command to determine the booted kernel name.

We can invoke the following command to determine the kernel name:

/etc/kernel -qu `ls -d /stand/unix* /unix* 2>/dev/null | sed 's/^/-e /'`
This command makes the kernel(ADM) utility perform a heuristic
check (similar to the one contained in method 2 below) of every
file of the form /stand/unix* and /unix* to find out if the file
corresponds to the booted kernel.  This utility will return the
name of the first file in the list of those examined which passes
the check.  In addition, this command (by way of -u option) creates
a file /etc/ps/booted.system containing information about the
booted kernel, if the command is successful.

2. Use your own method to determine the booted kernel name.

The simple shell procedure below runs the "ps.nlist" program
whose C source code follows the script.  You must have an SCO
OpenServer 5 Development System in order to compile and run this
program.  The directory containing the ps.nlist binary is assumed
to be part of the user's PATH.  The program should only be run as
root because of the default permissions on the files involved.
for kernel in /stand/unix* /unix*; do
  [ -f $kernel ] && ps.nlist $kernel
done
/****** C program to determine booted kernel * cut here ***********/
/*
 * ps.nlist.c--compile with "cc -o ps.nlist ps.nlist.c"
 *
 *
 * A program which determines whether a given kernel namelist
 * matches the booted kernel in memory
 */
#include <nlist.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/utsname.h>
#include <errno.h>
#include <string.h>
struct nlist sconame[] = {
"scoutsname",   0,      0,      0,      0,      0,
0,              0,      0,      0,      0,      0,

}; struct scoutsname nl_uname; struct scoutsname real_uname; int fd; int docomp();

main(argc, argv)
        int argc;
        char *argv[];
{
        if (argc < 2)
        {
                fprintf(stderr,"Usage: ps.nlist <namelist>\n");

exit(1); } /* call nlist(S) to fill out values in names[]; open /dev/kmem, readonly; call docomp() to read the scoutsname struct, compare the result with __scoinfo(), return the result */ if (nlist( argv[1], sconame ) == -1) { fprintf(stderr, "nlist error: could not read %s: %s\n", argv[1], strerror(errno)); exit(1); } if ((fd = open( "/dev/kmem", O_RDONLY )) == -1) { fprintf(stderr, "can't open /dev/kmem for reading: %s\n", strerror(errno)); exit(1); } if (docomp() == 0) { printf("Booted kernel is %s\n", argv[1]); exit(0); } else { printf("Booted kernel is NOT %s\n", argv[1]); exit(1); } }

/* * docomp() * * lseek, read the scoutsname struct from /dev/kmem using nlist'd name, * Compare to "correct" info returned from __scoinfo() */

int docomp()
{
        if (__scoinfo(&real_uname, sizeof(real_uname)) == -1)
        {
                fprintf(stderr, "__scoinfo() failed: %s\n", strerror(errno));
                exit(1);
        }
        if (lseek(fd, sconame[0].n_value, SEEK_SET) != sconame[0].n_value)
        {
                fprintf(stderr, "lseek() of /dev/kmem failed: %s\n",
                        strerror(errno));
                exit(1);
        }
        if (read(fd, (char *)&nl_uname, sizeof(nl_uname)) != sizeof(nl_uname))
        {
                fprintf(stderr, "couldn't read entire utsname structure\n");
                exit(1);
        }
        if (memcmp((char *)&real_uname, (char *)&nl_uname, sizeof(struct
            scoutsname)) != 0)
                return 1;
        return 0;
}
/************end program*****************/

See also

kernel(ADM) man page, for more information on using this command in relevance to the above discussion.

From the Xinuos technical article database, record 105690. Reproduced with permission. The original is at www.sco.com/ta/105690, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.