Monday, August 23, 2010

Unix Therory One Liners.

Type of Files

  • HardLink : Multiple path to same inode. Cannot Span different file system.
  • SoftLink : Alternate path to file. Can span file systems
  • Special Files : Kernel object represented as files. E.g Char,Block.
  • Pipes : IPC mechanism. Its supports one way communication within same process parent child realm.
  • FIFO : Also called Named pipes. IPC mechanism. Unrelated process can communicated.
  • Sockets : IPC mechanism. Two or more unrelated process can communicate. Two or more unrelated machines can communicate.

Process vs Threads

  • Process a program in memory. Running, and can be scheduled by the CPU. Takes memory / space.
  • Threads a unit of execution within a process. Shares most of the data structure of the process except the stack. Which is separate for each thread. Two threading library under UNIX is pthreads and NPTL .

  • fork() = creates a new process. New process is called the "child". Its an exact replica of the parent when its created. Its gets its own stack and heap on COW.
  • fork() returns twice, once for child (0) and other for parent ( pid of child ).

  • If child die before parent is called a zombie.
  • If parent die before child the child process is called an orphan.


What child process gets ...

  • All signal which are not ignored.

What child does not get ...

  • File locks in parent.
  • No pending signals.

  • exit() - Kills a process.
  • atexit() - Another variation of exit which calls an user defined method before exiting.

Parent getting status of child.

  • wait() - Parent retrieves information when child dies.
  • waitpid() - Get information of a single child whose pid matches.

Deamons = process running in background with not terminal attached.


I/O

  • Buffered I/O = Write / Read in buffers size. Can be forced to flush(). The opposite is non-buffered ( here user manages its own buffer write/read frequency ).
  • Multiplexed I/O = Write/Read with more than one file descriptors. ( select(), poll() )
  • Scatter/Gather Write/Read = Read/Write to many buffers in a single call.
  • MMAP = map file into memory.

Locking

  • Advisory = Not enforced. ( eg spin lock)
  • Mandatory = Enforced.
Signals

  • Are asynchronous notifications.

No comments:

Post a Comment