Transcript Kernal Unit

Unit – 1
Presented By
Mr. S. Gunasekaran
4300 Lines Added
1800 Lines Removed
1500 Lines Modified
PER DAY DURING 2007-2008
SUSE Lab
• The kernel is the "core" of any computer
system: it is the "software" which allows users
to share computer resources.
• XWindow environment doesn't belong to the
Linux Kernel
• avoid crash, OS designed with 2 different operative modes:
– Kernel Mode: the machine operates with critical data structure, direct hardware (IN/OUT or
memory mapped), direct memory, IRQ, DMA, and so on.
– User Mode: users can run applications.
• Kernel Mode "prevents" User Mode applications from damaging the system or
its features.
•
• When calling a System Call: after calling a System Call, the task voluntary calls
pieces of code living in Kernel Mode
• When an IRQ (or exception) comes: after the IRQ an IRQ handler (or exception
handler) is called, then control returns back to the task that was interrupted like
nothing was happened.
Switch
System
Call
IRQ
•
•
System calls are like special functions that manage OS routines which live in Kernel Mode.
A system call can be called when we:
–
–
–
–
access an I/O device or a file (like read or write)
need to access privileged information (like pid, changing scheduling policy or other information)
need to change execution context (like forking or executing some other application)
need to execute a particular command (like ''chdir'', ''kill", ''brk'', or ''signal'')
• When an IRQ comes, the task that is running is interrupted in order to service the
IRQ Handler.
• After the IRQ is handled, control returns backs exactly to point of interrupt
• The concept of a process is fundamental to any multiprogramming operating
system.
• A process is usually defined as an instance of a program in execution
• Process Descriptor
•
•
•
•
•
TASK_RUNNING
TASK_INTERRUPTIBLE
TASK_UNINTERRUPTIBLE
TASK_STOPPED
TASK_ZOMBIE
– Process execution is terminated, but the parent
process has not yet issued a wait( ) to return
information about the dead process.
• Identifying a Process
– lightweight processes—each process has its own
process Descriptor
• Process ID
– The PID is a 32-bit unsigned integer stored in the
pid field of the process descriptor.
– kill( ) use the PID
Linux stores two different data structures for each
process in a single 8 KB memory area
 the process descriptor and the Kernel Mode
process stack.
The process descriptor starts from the beginning of
the memory area and the stack from the end.
• circular doubly linked list
• Hash Table
•
•
•
•
•
p_opptr (original parent)
p_pptr (parent)
p_cptr (child)
p_ysptr (younger sibling)
p_osptr (older sibling)
• In order to control the execution of processes, the
kernel must be able to suspend the execution of the
process running on the CPU and resume the
execution of some other process previously
suspended. This activity is called process switching ,
task switching, or context switching.
–
–
–
–
Hardware context
Hardware support
Linux code
Saving the floating point registers
• The clone( ), fork( ), and vfork( ) System Calls
• Kernel Threads
– kernel_thread( )
• Destroying Processes
–
–
–
–
exit( )
All process terminations are handled by the do_exit( ) function
Wait()
The release( ) function releases the process descriptor of a
zombie process
• On Linux, kernel threads are created with the clone system
call. This system call is similar to fork in that it creates a task
which is executing the current program. However it differs in
that clone specifies which resources should be shared. To
create a thread, we call clone to create a task which shares as
much as possible: The memory space, file descriptors and
signal handlers. The signal to be sent when the thread exists is
SIGCHLD so wait will return when a thread exits.
• A signal is a very short message that may be sent to a
process or to a group of processes.
• Signals serve two main purposes:
– To make a process aware that a specific event has occurred
– To force a process to execute a signal handler function included
in its code
• Linux scheduling is based on
– time-sharing technique
• Quantum slice
– ranking processes
• Priority
• Interactive processes
• Batch processes
• Real-time processes