Understand System Maintenance Mechanics
- System calls are functions implemented by the Kernel, but are meant to be called in user space.
- Kernel 5.3 for example has 340 system calls.
- When have the Linux Kernel source code, can look at the
include/uapi/asm-generic/unistd.hfile to see all of the system calls. asmis Assembly Langauge.- System calls vary between architecture, x86-64 and ARM changes.
- Functions users can call are in the
manpages. - For example, if you look up
readin the manual, it is called through the standard library (libc) - Standard library uses architecture-dependent means to invoke the system call mechanism.
- Protocol and Library which tells the Kernel which system call to make.
- Suitable sised parameters are placed into registers.
- Kernel is invoked via the library, determines the system call and then calls it.
- If there is an error, the system call returns a negative value (function in the Kernel) to the library.
- If that value is negative, the library is going to set a global variable in the process address space. This error is called
errornotoabs(absolute value or return value) and returns -1 back to the program. The error number provided has information on what the error is. - The library is what sets
errorno.- When there is
noerror, the library does not seterrornoand returns the value it obtained from the Kernel.
- When there is
- Useful shell shortcut –>
grep -i read !$- The
!$means it will read the last thing on the previous line.
- The
- If you download the Kernel source code, go to
/usr/src/line-(number)/include/uapi/asm-generic. An example link is:howard@skwigelf:/usr/src/linux-headers-5.15.0-100-generic/include/uapi/asm-generic - To get an estimate of the number of system calls, we can do the following in the above directory:
grep "define __NR" unistd.d
- Don’t confuse user-space header file adnd Kernel space header files.
- Can check the
manpage forreadfor further information. - System Call
manpages have sections in the top-right hand corner, for exampleKILL(1)says we are in the first section of thekillcommand’smanpage. kill -9willkilla process.- To go to another section in a
manpage, we performman 2 killfor example. - RETURN VALUE is always listed in each library.