Skip to content

Commit

Permalink
posix: patch to implement get_pid function
Browse files Browse the repository at this point in the history
patch to implement get_pid function

Signed-off-by: Jai Arora <infolinesoni@gmail.com>
  • Loading branch information
jaiiarora committed Jan 5, 2024
1 parent 68066df commit ad92425
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/zephyr/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
extern "C" {
#endif

typedef int pid_t;

#ifndef __useconds_t_defined
typedef unsigned long useconds_t;
#endif
Expand Down
1 change: 1 addition & 0 deletions include/zephyr/posix/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions lib/posix/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <zephyr/logging/log.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/posix/pthread.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>

Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit ad92425

Please sign in to comment.