Tag Info

New answers tagged


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 ...


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) { ...


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 ...


Mysql doesn't have a kernel module, therefore it runs in user mode. Perhaps what you are seeing is that mysql is using memory-mapped files instead of calling read/write. So, accessing a page of memory causes a read/write without using a syscall. Or, perhaps you called strace without "-f" to follow the child processes?


According to _syscall(2) man page the _syscall0 macro may be obsolete and requires #include <linux/unistd.h>; indeed Linux 4.x don't have it However, you might install musl-libc and use its _syscall function. And you could simply use the indirect syscall(2) in your user code. So your testing program would be #define _GNU_SOURCE /* See ...


Well then assuming the instructor wants people to read the source and not just cut and paste from the internet, it's arguably a well-designed assignment. (That said, linux kernel code is not super nice to read. Make sure you know how to use etags, because often you have to trace macros three levels deep to see what is going on.)

Top 50 recent answers are included