The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: random PID generation
Date: 22 Feb 2001 13:42:56 -0800	[thread overview]
Message-ID: <974150$a9u$1@cesium.transmeta.com> (raw)
In-Reply-To: <27525795B28BD311B28D00500481B7601F0EEE@ftrs1.intranet.ftr.nl> <20010222232423.A18448@home.ds9a.nl>

Followup to:  <20010222232423.A18448@home.ds9a.nl>
By author:    bert hubert <ahu@ds9a.nl>
In newsgroup: linux.dev.kernel
> 
> Well - I'm not sure that this is a good idea. When PIDs increase
> monotonically, chances are very small that the race condition implicit in
> sending any signal to a process results in killing the wrong process (ie, a
> new process, but with the same PID) - you'd need to zoom through 32000 PIDs
> in a very short time to make this happen.
> 
> With truly random PIDs, there is a much larger chance of a new process
> sitting on a recently used PID.
> 
> What would work is to have cryptographically randomly generated PIDs which
> would then guarantee not to return a previously returned number within 32000
> tries, and also not be predictable - there must be algoritms out there which
> do this.
> 

It depends on the size of your number space.  If you have a 31-bit
pid_t (since it apparently must be sign-safe) then you can take random
16-bit numbers from the /dev/urandom code and add to the last used
value instead of simple increment.

	-hpa

-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt

  reply	other threads:[~2001-02-22 21:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-22 15:35 random PID generation Heusden, Folkert van
2001-02-22 22:24 ` bert hubert
2001-02-22 21:42   ` H. Peter Anvin [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-02-23 13:20 Heusden, Folkert van
2001-02-23 14:18 ` bert hubert
2001-02-23 15:34 Heusden, Folkert van
2001-02-23 15:40 ` Matt Johnston
2001-02-23 17:14   ` Sean Hunter
2001-02-23 17:50     ` Richard B. Johnson
2001-02-27 10:35 Heusden, Folkert van

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='974150$a9u$1@cesium.transmeta.com' \
    --to=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox