setpgid non-compliance with POSIX?

Jeremy Drake cygwin@jdrake.com
Tue Jul 1 18:16:50 GMT 2025


On Tue, 1 Jul 2025, Brian Inglis via Cygwin wrote:

> On 2025-06-30 13:07, Jeremy Drake via Cygwin wrote:
> > On Mon, 30 Jun 2025, Corinna Vinschen via Cygwin wrote:
> >
> >> Off the top of my head I don't know how to check the pgid already exists.
> >> Do you?
> >
> > I think it'd have to iterate all processes and check pgid and sid members
> > of pinfo until it found a match.
>
> Shouldn't need to - pgid is the pid of a process spawned by init, or pid of a
> login shell, and sid is that pgid or that of the parent process, or pgid is
> that
> of a job shell or of the parent process.

In practice, perhaps, but in theory it could get more complicated than
that.

> So each process sid also pgid is either its pid or that of its parent process:
> they are only set either to the process pid or inherited.

Not just parent, but could be inherited any level of ancestor, including
ancestors that then terminate, leaving the process adopted by init.  Also,
the restrictions given by POSIX seem to allow setting pgid to a
sibling/cousin/aunt/uncle as long as they have created a pgid (by
setting it to their pid) and are in the same sid.

> Try head /proc/self/*id & and head /proc/$$/*id as demos.
>
> Does any of that help? ;^>
>

Not really :P  I hope I don't have to write more test cases for some of
the complicated scenarios I envision being legal under the POSIX docs, I
feel like I've caused enough trouble already with the test cases I've
written trying to exercise posix_spawn :)


More information about the Cygwin mailing list