Tag Info

Hot answers tagged

10

The kernel does job scheduling and provides system calls. When a process is running, the kernel schedules its runtime - especially it assigns a PID to it - such information is stored inside the kernel address space, in data structures (e.g. inside a task struct). Thus, when a process calls the getpid() system call, the kernel just has to look in the task ...


5

When a system call is executed, there is a privilege switch, i.e. the executed code is allowed to execute more instructions and access data forbidden to userland code. There is however no process context switch so the kernel code is still running in the calling process context. That means the kernel does not need to search which process is calling it, it ...


4

In a single CPU system, there is a global variable that points to the proc structure of the running process or the current thread. The proc structure contains the process id. In a multi CPU system, there is either a similar pointer for every CPU or the MMU context is used to set up such a global variable for the syscall. int64_t getpid(void) { ...



Only top voted, non community-wiki answers of a minimum length are eligible