bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: Martin Oberzalek <martin.oberzalek@ssi-schaefer.com>
Cc: bug-gnulib@gnu.org
Subject: Re: pid_t on 64-bit Windows
Date: Tue, 01 Sep 2020 12:25:10 +0200	[thread overview]
Message-ID: <2878350.UOmnhqlPMq@omega> (raw)
In-Reply-To: <1598922690.7789.35.camel@ssi-schaefer.com>

Martin Oberzalek wrote:
> What I wan't to point out is that in gnulib on WIN32 API pid_t is not a process id 
> like it is on linux. Functions in gnulib that are using pid_t eg waitpid() accepting
> a process handle instead.

Correct.

When an OS offers process handles, instead of pids, we better should use that,
because it eliminates race conditions. (When a program uses waitpid() or kill() with
a pid argument, there is the risk that the intended process was already killed and
the pid was reused by another process. The probability that this happens is small,
which is why the problem is ignored in the Unix word. Nevertheless, a handle should
be more reliable.)

On Windows, the basis of waitpid() is '_cwait', which is essentially the same as
WaitForSingleObject. No race condition.

> I'm using parity[1] in an gentoo prefix environment to compile in linux like style
> win32 as win64 applications. 
> 
> parity is a wrapper around the visual stdio compiler

That's all ok...

> and it defines pid_t as int.

This isn't ok. As explained above, the more reliable implementation of waitpid
takes a 64-bit HANDLE (on _WIN64) as argument, not a 32-bit int.

> Because getpid() return also int. And GetCurrentProcessId() as well.

This is a red herring, because no one will call waitpid() to wait for the
current process. waitpid() is always used to wait for a different process,
typically even subprocesses.

mingw defines pid_t as 64-bit on _WIN64. Mingw make-alikes like parity should do
the same.

Bruno



  reply	other threads:[~2020-09-01 10:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-23 23:30 pid_t on 64-bit Windows Bruno Haible
2020-08-31  8:13 ` Oberzalek Martin
2020-08-31 14:27   ` Bruno Haible
2020-09-01  1:11     ` Martin Oberzalek
2020-09-01 10:25       ` Bruno Haible [this message]
2020-08-31 11:15 ` Oberzalek Martin

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

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

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

  git send-email \
    --in-reply-to=2878350.UOmnhqlPMq@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=martin.oberzalek@ssi-schaefer.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).