Kernel
- The kernel is the core of the operating system.
- Taken from (http://harish-kayarohanam.blogspot.com/2011/12/ltrace-and-strace.html)
- Users interact with the kernel mostly via the shell
- Applications are started by the shell (mostly)
- The shell and all applications interact with the kernel via system and library calls.
- Our book lists the following as activities performed by the kernel
- Process scheduling: Linux uses preemptive multitasking
- Multitasking : multiple processes appear to run at the same time.
- Each is given a share of time on the cpu
- But a process can be interrupted to allow another process to run.
- And this occurs across multiple processors
- This is done by a portion of the kernel called the scheduler
- This is a 1 minute statement about several weeks in OS and perhaps a lifetime of study.
- Memory Management
- Each process has a portion of allocated memory
- The kernel makes sure that one process does not have access to the memory of another process.
- Unless, of course, they want to share memory.
- And that kernel memory is protected.
- It also takes care of where data is stored
- Real memory
- Hard drive
- And if part of this memory is shared. (libc for example)
- The file system
- The kernel is responsible for the actual layout of the files (bits) on the disk.
- Devices
- All device interaction is handled through the kernel.
- API
- There are generally two modes in which the cpu operates
- User mode : access to memory is restricted.
- Kernel mode, or supervisor mode: access is unrestricted.
- Some instructions are only permitted to be executed in kernel mode (halt)
- A system call is required to extract information from kernel space to user space.
- Looking for the kernel
- Tools:
- ps shows the running processes on the system.
- top is an interactive tool to do the same.
- Each of these shows a snapshot of what processes are running on the system.
- Some important fields:
- PID or process id, unique to each process
- User, who started the process
- command: the command line argument (probably) used to start the process.
- pid 1 is the system spawner
- It is not the kernel, it is the first process started by the kernel when it goes multiuser
- It was called init but seems to have become systemd
- Processes with commands in brackets are most likely something started by the kernel (These are manifestations of the kernel)
- And low level pids are reserved for system processes.
- kthreadd for example
- It is apparently difficult to start a thread in kernel space
- So this daemon is implemented to allow for the kernel to start threads
- Anything with a ppid of 2 is probably part of the kernel.
- So we see parts of the kernel, but we don't really see the kernel.
- That is because it somewhat doesn't exist.
- At least not as a process.
- But more on that later.