diff --git a/include/zephyr/posix/posix_types.h b/include/zephyr/posix/posix_types.h index 175943950b7c..3420d562679b 100644 --- a/include/zephyr/posix/posix_types.h +++ b/include/zephyr/posix/posix_types.h @@ -21,6 +21,8 @@ extern "C" { #endif +typedef int pid_t; + #ifndef __useconds_t_defined typedef unsigned long useconds_t; #endif diff --git a/include/zephyr/posix/unistd.h b/include/zephyr/posix/unistd.h index b55cf702fec2..84faf7c1c8f2 100644 --- a/include/zephyr/posix/unistd.h +++ b/include/zephyr/posix/unistd.h @@ -51,6 +51,7 @@ extern char *optarg; extern int opterr, optind, optopt; #endif +pid_t getpid(void); unsigned sleep(unsigned int seconds); int usleep(useconds_t useconds); diff --git a/lib/posix/pthread.c b/lib/posix/pthread.c index 131242866a05..2e2c49f2a35b 100644 --- a/lib/posix/pthread.c +++ b/lib/posix/pthread.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,22 @@ int pthread_equal(pthread_t pt1, pthread_t pt2) return (pt1 == pt2); } +pid_t getpid(void) +{ + /* + * To maintain compatibility with some other POSIX operating systems, + * a PID of zero is used to indicate that the process exists in another namespace. + * PID zero is also used by the scheduler in some cases. + * PID one is usually reserved for the init process. + * Also note, that negative PIDs may be used by kill() + * to send signals to process groups in some implementations. + * + * At the moment, getpid just returns an arbitrary number >= 2 + */ + + return 42; +} + static inline void __z_pthread_cleanup_init(struct __pthread_cleanup *c, void (*routine)(void *arg), void *arg) {