From: Paul Eggert <yyyyyy@xxxxxxxxxxx>
> Date: Tue, 13 Mar 2001 20:55:08 +0100 (MET)
> From: yyyyyyyyyyyyyyy@xxxxxx
>
> It seems to me that a routine like
> void outpid(pid_t p) {...}
> prints a pid without making assumptions on the size of a pid.
Something like that 'outpid' can be made to work, and I've done it
myself for off_t (several times :-). But it is a pain to maintain and
use such routines. Even assuming outpid is entirely bug-free (which
your wasn't -- it failed if -p overflowed)
:-) I was sure that you were going to say this.
printf(_("process ID = %ld, parent process ID = %ld\n",
(long)getpid(), (long)getppid());
is much easier to write
Of course.
We have had this discussion already so our points of view
are clear:
me: (i) there is no theoretical problem - it is possible to program
correctly without assumptions on the size, and (ii) for people who
think that in practice a pid_t is not going to be wider than a long
there is a more convenient version.
you: (i) I want the convenient version, (ii) I want to program in
the full generality allowed by POSIX, so request that POSIX restrict
possibilities so much that full generality is covered by the
convenient version.
My opinion is that your argument is not strong enough,
but you have many supporters. One reason I am somewhat interested
in this particular point (I mean pid_t) is that a 64-bit pid_t
makes process creation much more efficient in a context of a
highly parallel machine. (When pid's can be repeated, as is certainly
common for 16-bit and possible for 32-bit pid's, one has to search
the list of processes before giving out a new pid, since a new process
must have pid, pgid, session different from existing ones. And if there
are many processes the search takes long, or requires special
data structures. Moreover, locks are required to keep the other
CPUs away from the process lists while one does this search.
With a 64-bit pid things are much more efficient - essentially
it is just
pid_t newpid() {
static pid_t next_pid = 1;
return next_pid++;
}
So, even when one does not expect to have more than a few thousand
processes at any given point of time, it is useful to have a pid_t
so large that no repetition will ever occur.
(Maybe I already said the same things earlier. No doubt you'll answer
that people who need this big machine with many short-lived processes,
say a big web server, and want this speed gain, must buy a 64-bit machine.))
Andries
|