Bug 13198

Summary: sched.h should define pid_t
Product: glibc Reporter: Bruno Haible <bruno>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: aj, eblake
Priority: P2 Flags: fweimer: security-
Version: 2.11   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Bruno Haible 2011-09-18 21:22:00 UTC
According to POSIX:2008
<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html>
the <sched.h> header should ensure that the pid_t type gets defined, like
<sys/types.h> does, if the "Process Scheduling" features of POSIX are supported.

In this header, these features consist of the functions sched_get_priority_max,
sched_get_priority_min, sched_getparam, sched_getscheduler, sched_rr_get_interval,
sched_setparam, sched_setscheduler - which are all supported by glibc.
So I believe the intent is that glibc supports the "Process Scheduling" features.
But then <sched.h> should define 'pid_t'.

How to reproduce:
================= bug.c ================
#include <sched.h>
pid_t x;
========================================

$ gcc -c bug.c
bug.c:2:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'
$ gcc -c -D_GNU_SOURCE bug.c
bug.c:2:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'
Comment 1 Eric Blake 2011-09-19 22:15:42 UTC
This appears to be fixed by at least glibc 2.13:

$ printf '#include<sched.h>\n' | gcc -E - | grep pid_t | head -n2
typedef int __pid_t;
typedef __pid_t pid_t;
$ printf '#define _POSIX_C_SOURCE 200809L\n#include<sched.h>\n' \
  | gcc -E - | grep pid_t | head -n2
typedef int __pid_t;
typedef __pid_t pid_t;
Comment 2 Andreas Jaeger 2011-09-28 12:21:35 UTC
This is fixed in current glibc (tested 2.14).