0% found this document useful (0 votes)
13 views

01 Linux Introduction

The document provides an introduction to Linux including its kernel features, components, portability, fundamental concepts like the difference between a program and process and various process states. It also discusses user space vs kernel space and limitations of user space programming.

Uploaded by

Kimmi Bansal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

01 Linux Introduction

The document provides an introduction to Linux including its kernel features, components, portability, fundamental concepts like the difference between a program and process and various process states. It also discusses user space vs kernel space and limitations of user space programming.

Uploaded by

Kimmi Bansal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to Linux

Copyright 2003 - ATR Labs - All Rights Reserved.

Linux features in a nutshell


1. 2. 3. Monolithic kernel. ( NOT DERIVED FROM UNIX, REWRITTEN FROM SCRATCH ) Statically compiled + support for dynamic extension through LKMs Limited support for kernel threading. Kernel threads do not support user processes.

4. Multithreaded application support. Linux defines its own version of LWPs ( Light weight processes ) using a nonstandard system call clone, while all other unix versions use kernel threads to implement LWPs. 5. 2.4.x version of the kernel is non-preemptive while running in privileged mode. The 2.6 version allows pre-emption as an optional feature. 6. 7. 8. 9. Multiprocessor support. Support for several filesystems. Unix STREAMS I/O is not part of the kernel. Separately maintained. FREE / FAST / POWERFUL / COMPACT / RELIABLE / SUPPORTED

10. Version numbering X.Y.Z ( X => version. Y=even => stable else development. Z = stable / dev release ).

Understanding The Linux Kernel


Components:
1. Process Management 2. Memory Management 3. File Systems 4. Device Management 5. Networking

V.Radhakrishnan 2002.

Linux Portability
Linux runs on a very large number of hardware: Special PCs : SGI-Linux, MCA Linux, NEC PC-98 Linux IA-64 Motorola SPARC Compaq ARM : 68K, Linux Power PC or PPC : SunSparc, UltraLinux : VAX Linux, Linux Alpha : ARM and Strong ARM

Linux/MIPS : SGI, Cobalt, DEC, Nintendo 64 HandHelds : Crusoe, Palm, ELKS, VME, Linux CE

Microkernels : MkLinux RealTime : Lineo : MOSIX, Beowulf, Linux SMP

SMP/Clustering IBM Misc.

: 370/390, AS/400, 4758 : Fujitsu, PA-RISC

Fundamental Concepts
Difference between a "Program" and a "Process"
A Program is a complete set of executable instructions on the hard disk. A Process is created when the program is loaded into memory. A process space has DATA, STACK and INSTRUCTIONS. It has an ID ( Identification ) and exists as long as it is required to run. The same program can be run (loaded) twice. There will be two program). processes (but only one

The kernel is responsible for :


a. creating and destroying processes. b. Inter Process Communications. c. processes to communicate with the outside world (Input/Output ).

V.Radhakrishnan 2002.

A Process's View Of the Kernel

CPU, Memory, Devices, NICs,...

Kernel = Black Box "Provider Of Services"

My CPU My Memory

My CPU My Memory

My CPU My Memory

Process-1
V.Radhakrishnan 2002.

Process-2

Process-3

The Internal View Of the Kernel


Process-1 Process-2 Process-3

Seen fromoutside
Task - 1 Task - 2 Task - 3

Seen from inside

The Task Queue

Task-1

Task-2

Task-3

Task-1

Task-3 Task-1

Task-2 Task-3

Task-1

Process-2 over Process-3 over


V.Radhakrishnan 2002.

Process-1 over

The Various Process States....


Running

The task is active and running in the non-privileged User Mode. This state can only be exited via an interrupt or a system call. ( System calls are a special case of interrupts ). In either case, the processor is switched to the privileged mode and the appropriate interrupt routine is activated. The process is competing for the processor, which is however occupied with another process at the present time. Its ready to execute and will be executed at the first available moment.

Ready "runnable"

The process is waiting for an external event. Only after this has occurred, will it continue its execution.
Waiting "blocked"

Two kinds of "Waiting Processes" Interruptible - processes can be interrupted by signals uninterruptible - waiting ONLY for hardware conditions

V.Radhakrishnan 2002.

The Various Process States

Return from System Call

Running

System Call Waiting Ready

Running

Interrupt

Scheduler
Interrupt Service Routine

V.Radhakrishnan 2002.

CPU Switch From Process to Process

Difference between User Space & Kernel Space


Multi-user Operating Systems. One user -> can execute several programs simultaneously. Programs require access to hardware / resources. Need for protection of these resources. O.S needs to provide this protection. This can ONLY be achieved if the CPU cooperates with the O.S to enforce access. CPUs provide support by running at different levels. Unix / Linux use two levels ( though CPUs map provide more) Under Linux, the kernel code executes at the highest level, whereas user code executes at the lowest level. We usually refer to Kernel Space and User Space since in addition to processor privilege levels, each mode has its own memory mapping as well. Linux transfers execution from user space to kernel space whenever an application issues a system call or whenever an application is suspended by a hardware interrupt. Triggering a 0x80 interrupt switches processor to higher level. Kernel code executing a system call is working in the context of a process. It will be able to access data in the process's address space. Interrupt handling code however is asynchronous with respect to processes.

V.Radhakrishnan 2002.

Rings of Protection

Privilege Levels 3 Most Privileged 2 1 0 Private OS functions OS Services Device Drivers Application programs Least Privileged

Note: Though the x86 processor provides 4 levels, Linux only uses 2 of the ring levels to enforce Kernel Mode and User Mode levels.
V.Radhakrishnan 2002.

User Space Programming Limitations


1. Interrupts are NOT AVAILABLE in user space. 2. Direct access to memory is only possible by mmapping /dev/mem and only a superuser can do that. 3. Access to I/O Ports is available only after calling ioperm or iopl, and only a privileged user can do that. 4. Response time is slower because a context switch is required to transfer information.

However, in spite of the above limitations, some applications have drivers written in the User Space.
Advantages of using the User Space mode for writing drivers: 1. The full C library can be linked in. This is NOT possible when programming in kernel mode. 2. A conventional debugger can be run without the extra effort involved in trying to debug a running kernel. 3. If a user space driver hangs, you can just kill it. Problems with the driver are unlikely to hang the entire system. 4. User memory is swappable. Infrequently used device with a huge driver could be swapped out, unlike a driver written in the kernel mode, where it doesnt get swapped out. Examples of user space drivers are the X Server, the gpm mouse server, the libsvga program, SANE, cdrecord etc...

V.Radhakrishnan 2002.

Linux is Re-Entrant.
Mainline Driver Procedure 7 1 Call Driver 2 3 4 Interrupt occurs 11 12 7 10 9 Interrupt Procedure 5 Call Driver 6

13 8 The Linux Kernel as well as driver code needs to be re-entrant. The Linux Kernel is NOT PRE-EMPTIVE, which means that a process can be pre-empted only when running in User Mode. ( Changed in Linux 2.6 !! ) V.Radhakrishnan 2002.

Web Links: 1. 2. 3. 4. 5. 6. www.kernel.org www.lwn.net www.tldp.org www.freshmeat.net www.kernelnewbies.org www.linuxdevices.com

Linux-Journal, Linux-Gazette, Embedded Linux Journal.

You might also like