15
Linux Kernel introduction COSC 513 Xiaoping Yang

Linux Kernel introduction COSC 513 Xiaoping Yang

Embed Size (px)

Citation preview

Page 1: Linux Kernel introduction COSC 513 Xiaoping Yang

Linux Kernel introduction

COSC 513Xiaoping Yang

Page 2: Linux Kernel introduction COSC 513 Xiaoping Yang

What is LinuxA 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

Page 3: Linux Kernel introduction COSC 513 Xiaoping Yang

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

Page 4: Linux Kernel introduction COSC 513 Xiaoping Yang

What inside Linux Kernel

Linux kernel Kernel contains:

System Call interface

Memory Manager

File System

Network support

Linux Kernel is a monolithic kernel

Page 5: Linux Kernel introduction COSC 513 Xiaoping Yang

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)

Page 6: Linux Kernel introduction COSC 513 Xiaoping Yang

Linux SchedulerMulti-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

Page 7: Linux Kernel introduction COSC 513 Xiaoping Yang

Process TreeThere 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 )

Page 8: Linux Kernel introduction COSC 513 Xiaoping Yang

Process Tree (cont.)

Page 9: Linux Kernel introduction COSC 513 Xiaoping Yang

Task TreeFor 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 stateOwner:

UIDGID

Page 10: Linux Kernel introduction COSC 513 Xiaoping Yang

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.

Page 11: Linux Kernel introduction COSC 513 Xiaoping Yang

Linux Process State

Page 12: Linux Kernel introduction COSC 513 Xiaoping Yang

Interrupts and System CallsAn 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

Page 13: Linux Kernel introduction COSC 513 Xiaoping Yang

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

Interrupts and System Calls (cont.)

Page 14: Linux Kernel introduction COSC 513 Xiaoping Yang

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

Fast Interrupts in Linux

Page 15: Linux Kernel introduction COSC 513 Xiaoping Yang

END