how to get a Process ID in c, getpid() is not implemented

1.1k views Asked by At

How can I get the process ID in C while getpid() method is not implemented ? I ve got an OS without anything, no libraries, nothing, I have to develop all.

1

There are 1 answers

5
Mats Petersson On

Nobody here will be able to give an exact answer for an OS that isn't generally available (unless they are or have been in the same course as you)

The generic answer is that you need to introduce a new system call (if the OS is really simple, this would be just a function call, like other OS services - without knowing the OS itself, it's a detail that can't be concretely answered), that checks what the current process is, and returns some form of unique number for that process ID. Could be the pointer to the process control block [as in Windows], the stack pointer [if the OS doesn't have virtual memory so stack is at the same place], or the number of the current process's entry in the process list.