TimeLinux1

Sunday, April 17, 2011

Linux: OS Basics - 2

... continued ...

-process    - a program in execution.
-the program file exists on the disk. To execute, it must be read from disk to memory where the cpu operates on it.
-the process is fundamentally a container that holds all the info needed to run a program.
-every process is uniquely identifiable by its process id or pid.
-address space    - the space in memory where the process exists.
-This means, every process has an associated address-space, every process needs a container.
-address space values are from zero to a certain maximum.
-In a multi-programming system where multiple programs compete for cpu-time, the kernel does this:
    . listen to system calls from processes
    . upon system call traps, the kernel freezes the info in a processes's address space & saves it
    . then the kernel assigns another process to run on the cpu.
    . the kernel repeats the above on and on.
-note: a process must be resumed from exactly the same state that it was saved in memory.
-the info in the address-space is:
    . the executable program    - the code
    . program's data         - the variables and temp values
    . program's stack        - resources, counter, open-files, alarms etc.
-process table    - is a table maintained by the kernel.
-process table has info about every running process and their address space.
-for a given system, addressable space is 2tothepowerN where N is the cpu bitsize (eg 32bit or 64bit).
-if main memory is less than the addressable space, virtual memory is helpful.
-together they can map the entire addresable space.

-in contrast to processes that have independent address-spaces what if two lines of execution have same address space?
-threads are exactly that. threads are execution structures having a shared address space in memory.
-threads form part of a process. in other words a process can have multiple threads.
-threads improve efficiency by parallelizing execution of instructions for a process.
-threads are especially more efficient and relevant in multicore chips.
-in nutshell, threads are like mini-processes that exist in user space (since they are subset of a process)


-System calls - a mechanism for the user programs to communicate with the kernel.
-In Posix, there are about 100 standard system calls.
-In contrast, windows has thousands of calls (usually called API calls).
-note: from previous discussion, remember, user programs exist in user-space and kernel exists in kernel-space.
-examples of system calls - fork, exit, open, read, write, close, kill etc.
-to create a new process, an existing parent process forks and creates an identical copy of itself.
-the identical copy has its own address space and pid.

-kernels can be of two types - micro-kernel and mono-lithic.
-microkernel OS are more modular and a small set of modules runs in kernel mode. All else is in user space.
-eg: device drivers are in the user-space and bugs in a driver crash only it, not the system.
-microkernel os may be modular and seemingly secure but not necessarily fast.
-eg: Minix, Symbian, PikeOS.
-monolithic kernels are not so modular.
-they have a big chunk of modules running in the kernel mode and very few in user-space.
-eg: all device drivers in exist as part of the kernel.
-monolithic os may be bit bigger but are faster as most of the modules are already compiled and ready to go.
-eg: Unix, Linux.

... continued ...

No comments:

Post a Comment