170 likes | 441 Views
Linux Kernel introduction. COSC 513 Xiaoping Yang. What is Linux. A clone of Unix operating system Provides for the efficient management of system resources: Linux is almost a freeware First developed for 32-bit x86-based PCs (386 or higher). Three major components: Kernel
E N D
Linux Kernel introduction COSC 513 Xiaoping Yang
What is Linux • A clone of Unix operating system • Provides for the efficient management of system resources: • Linux is almost a freeware • First developed for 32-bit x86-based PCs (386 or higher). • Three major components: • Kernel • Shell Environment • File structure
What is the Linux Kernel? • The Heart of the Linux Operating System • Provides for the efficient management of system resources: • CPU • Interprocess Communication • Memory • Devices: • Disks • Terminals • Networks • Printers
What inside Linux Kernel Linux Kernel is a monolithic kernel • Linux kernel Kernel contains: • System Call interface • Memory Manager • File System • Network support
Linux Processes and Tasks • Linux Process = Executing Program Linux Task is a generalization of a Thread • Single threaded process is represented as a task • Multi-threaded process is multiple tasks • Only visible to the programmer and the kernel. • The Scheduler decides which task(s) gets to use the CPU(s)
Linux Scheduler • Multi-level queue scheduler • Three queues • SCHED_FIFO - standard priority. • Highest priority. • No time-slice • "supervisor" processes only • SCHED_RR - priority round robin. • Highest priority RR runs for 1 time slice. • "supervisor" processes only • SCHED_OTHER - time-sharing • All Linux user processes
Process Tree • There is a tree like relationship among processes: Given the following: • $ netscape & • $ emacs & • $ xfig & • bash is the parent process • netscape, emacs and xfig are children of bash and are siblings • netscape is the oldest sibling • xfig is the youngest sibling • Linux stores this structure as linked lists • Linux will show you the tree (using ps f )
Task Tree • For every task the kernel maintains a task_struct task_struct contains all relevant information about a task. • General: • PID,Program name • Parent, youngest child, next sibling, previous sibling • Process Times (start_time, utime, stime, cutime, cstime) • Scheduling algorithm, priority, nice value, errno • Process state • Owner: • UID • GID
Task tree (Cont.) • Files: • Information on all files opened by the process. • Stored in the fs_struct sub-structure • Memory: • Information about the memory used by a process. • IPC / Synchronization: • Pointers to acquired Semaphores • Bitmask of received Signals and associated Signal handlers • Some other stuff... • Linux stores all task_structs in a doubly linked list.
Interrupts and System Calls • An interrupt is a request from the hardware for immediate attention. • Two types of interrupts in Linux: • Fast Interrupts • Suspend current task, process interrupt, resume task • All other interrupts are generally disabled • Keyboard interrupt • Mouse interrupt
Interrupts and System Calls (cont.) • Slow Interrupts • All registers are saved. • Only interrupts of same type are disabled. • Scheduler is called when ISR exits. • Timer interrupt • Disk Drive interrupt • System calls
Fast Interrupts in Linux • Suspend current task • Save CPU registers that might be altered • Switch CPU to kernel (system/supervisor/etc...) mode • Block all interrupts • Call Interrupt Service Routine (ISR) • Unblock interrupts • Switch CPU to user mode • Resume suspended task • Restore saved CPU Registers