TimeLinux1

Friday, May 27, 2011

Linux in Depth - 2

... continued ...

-Linux process management is similar to Unix but there are some imp differences.
-In Unix, process creation is a two step process:
    . a new process which is exact copy of the parent is created using the fork() system call.
    . the child is then allowed to run its own program using the exec() system call.
-the two steps are required for the following reasons:
    . step 1, fork(), is reqd bec otherwise the child will cause the termination of the parent process.
    . step 2, exec(), is reqd bec otherwise the child will continue running the same process as parent.
-in step 1, fork(), the child inherits the environment of the parent. eg: signals, address space, open files etc.
-in step 2, exec(), the child changes  the environment specific to the program to be run.
-To identify and manage a process the following properties are used by the os:
    . pid        -  for identification
    . credentials    -  for permissions
-also, a process may have one or more threads of execution within it.
-So the above was the Unix model of process management.

-in Linux, things are a little different.
-Linux does not differentiate between processes and threads.
-instead it refers to them as a third term called 'task'.
-task refers to a flow of control within a program. it resembles Unix threads.
-besides providing fork(), linux has a clone() system call that creates a task (like unix threads).
-one can think of clone() as a superset of fork().
-If the parent and child have the same env (signal, addr spc, files etc) then clone is equiv to fork.
-the main reason for this new model in Linux is efficiency.
-In Linux, the clone() call causes the context of a program to be stored in independent subcontexts.
-this independence of subcontexts helps in sharing resources between multiple processes.
-this means fewer resources can support more processes--which leads to increased efficiency in process mgmt.

-Linux filesystem behavior is similar to that of Unix.
-anything that can handle an input, output stream of data is treated as a file.
-as such, devices are treated as files as well and managed by special device files.
-device files may be of three types - block, character and network.
-block devices - allow random access to data blocks. eg hard disks, optic disks, flash etc.
-char  devices - allow serial access to data. eg keyboard, mouse, display
-netw  devices - allow access to data via kernel. eg remote servers, disks etc.

-the kernel is informed of an event via traps (by procs) and interrupts (by devices).
-the processes are informed of an event via signals.
-signals allow processes to talk to each other. this is called interprocess communication.
-signals also are used by kernel to talk to processes.
-signals do not transfer data but only info about events.
-besides signals, a pool of semaphores are also used for interprocess communication.
-like signals, semaphores do not transfer data but only info about events.
-the actual data is transfered between process using pipes and shared memory.

---xxx--

No comments:

Post a Comment