[comp.unix.questions] Max # of processes.

aj@zyx.UUCP (Arndt Jonasson) (06/22/87)

How can the maximum number of processes in a Unix system be determined?

Our system is HP-UX for HP9000/200 and HP9000/300, but preferably I
would like to know the most portable way of obtaining this value. We
don't have Unix source. HP-UX is essentially SYS5.2 with some BSD
extensions.

I have previously seen references to a symbol named NPROC, and there is
indeed one of that name referred to in the file /usr/include/sys/space.h,
but it isn't defined anywhere in /usr/include/... (which, it seems to me,
makes that include file quite useless).

I also thought of using nlist(3) to read the value of the appropriate symbol
from the kernel, but I didn't find any symbol that seemed to be the
right one.

The intended use is like this in a C program:

  typedef struct process {...} Process;
  Process proc_table[NPROC];

where I obviously don't want to make the array too small.

If there isn't a 'static' way to find out, this would do as well:

  int max_no_of_processes ();
  Process *proc_table;
  proc_table = (Process *) malloc (max_no_of_processes () * sizeof (Process));

-- 
Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden
UUCP: ...!seismo!mcvax!zyx!aj

josh@hi.UUCP (Josh Siegel) (06/26/87)

In article <845@zyx.UUCP> aj@zyx.SE (Arndt Jonasson) writes:
 >
 >How can the maximum number of processes in a Unix system be determined?
 >
 >Our system is HP-UX for HP9000/200 and HP9000/300, but preferably I
 >would like to know the most portable way of obtaining this value. We
 >don't have Unix source. HP-UX is essentially SYS5.2 with some BSD
 >extensions.
 >
 >I also thought of using nlist(3) to read the value of the appropriate symbol
 >from the kernel, but I didn't find any symbol that seemed to be the
 >right one.
 >

I am not sure about SYS5.2 but on BSD, there is a var called nproc and
I used nlist to get at it.  If this doesn't exist in SYS5.2, then..


-- 
Josh Siegel		(siegel@hc.dspo.gov)
  Friends don't let Friends eat Cherry Zinger1

jfh@killer.UUCP (John Haugh) (06/30/87)

The crash program has an option for looking at the struct var in 
the kernel that gives most of the size stuff.  The structure is
defined in /usr/include/sys/var.h.  The name of the variable in
/unix that contains the dude is _v (or whatever your compiler does
to a thing declared struct var v;)

If you want to know the maximum number of processes per user, that
would be MAXUPC rather than NPROC.  I suggest you print out the
include file if you don't have crash and then use adb or sdb on
/dev/kmem and look at the structure that way.  Should take less
time than writing a program.

- John.

rml@hpfcdc.UUCP (07/08/87)

> How can the maximum number of processes in a Unix system be determined?

Unfortunately there is currently no portable way to do this.

> Our system is HP-UX for HP9000/200 and HP9000/300

I'll assume that the series 200 machines are running some 5.x release
(the story is different for earlier releases).

> I have previously seen references to a symbol named NPROC, and there is
> indeed one of that name referred to in the file /usr/include/sys/space.h,
> but it isn't defined anywhere in /usr/include/... (which, it seems to me,
> makes that include file quite useless).

The number of processes is configurable.  <sys/space.h> is a unique file
that is only used during the configuration process.  It is included by
conf.c (which is built by config in the /etc/conf directory when
building a new kernel); the value of NPROC is defined in conf.c.  Space.h
is indeed not very useful for any other purpose that I know of.

> I also thought of using nlist(3) to read the value of the appropriate symbol
> from the kernel, but I didn't find any symbol that seemed to be the
> right one.

The symbol in this case is _nproc.  This will work for all 5.x releases
for the machines you described.  It will generally work on BSD-based
systems (with the possible exception of the leading underscore).  Of
course this or any other use of nlist is decidedly non-portable, even
among HP systems.  We can't even guarantee that it will continue to
work under future releases for the same system, though I see no reason
that this wouldn't.

Note that _nproc is the total number of process slots in the system,
certainly conservative for your purpose.  Another variable, _maxuprc,
holds the value of another configurable parameter, the maximum number
of processes for any user ID (except superuser).

> If there isn't a 'static' way to find out, this would do as well:
> 
>   int max_no_of_processes ();
>   Process *proc_table;
>   proc_table = (Process *) malloc (max_no_of_processes () * sizeof (Process));

The IEEE P1003.1 committee is looking at standardizing an interface of
this form (more general to get the values of more system parameters).
That is probably the most likely source of a portable mechanism.

Standard disclaimer: I'm speaking for myself, not HP, or IEEE, or P1003.1,
or...

		Bob Lenk
		{ihnp4, hplabs}!hpfcla!rml

jfh@killer.UUCP (John Haugh) (07/15/87)

In article <5740011@hpfcdc.HP.COM>, rml@hpfcdc.HP.COM (Bob Lenk) writes:
> > How can the maximum number of processes in a Unix system be determined?
> 
> Unfortunately there is currently no portable way to do this.
> 
i don't know.  most of the newer unix systems come with crash(1) and generally
it works.  now, if crash is broken, then what you say is true ...

- john

disclaimer:
	no disclaimer.

mats@forbrk.UUCP (Mats Wichmann) (07/21/87)

In article <1135@killer.UUCP> jfh@killer.UUCP (John Haugh) writes:

>i don't know.  most of the newer unix systems come with crash(1) and generally
>it works.  now, if crash is broken, then what you say is true ...

What does "broken" mean in this case? It works, but it certainly
isn't "portable"; it is one of the things that needs to be stepped
on (er, ported) for a new implementation. Nasty little bugger, too.

-mats