Thursday, September 9, 2010

UNIX process

UNIX process

process is a running instance of a program,identified with "pid"

process consist of
  • allocated system resources
  • a section of memory
  • security attributes (like its owner and set of permissions)
  • the process state(running,blocked,waiting)
  • process can also be called as execution context of a running program in the current time slice, which is given by the OS as part of scheduling the processes running in the CPU
  • process can also be defined in terms of data structure which stores the information about the process
  • new process is created by "fork" command in Unix
  • program is an executable file in binary format that can be read by the CPU, and process is a program in action (execution)
process control system provides services for
  • process scheduling, giving cpu time(divided into time slice) to each process, context switch(when time slice ends or the process waiting for a resource) from one process to other when execution context changes
  • context is the contents of the CPU register and the program counter
  • when context switch occur
  • when scheduling multiple tasks(from one process or thread to another), handling the hardware interrupt,user and kernel mode switching



context switch as done by the kernel
  • suspend the process and store its state(context) in memory
  • reterive the context of the next scheduled process from the memory
  • return to the location indicated by the Program Counter(the line where the process was interrupted)of the loaded process

process synchronization
between parent and child process

inter process communication
  • Asynchronous(sender and receiver are indepndent, and respond as their schedule permits, not bounded by some clock, not in sync)  signalling of events
  • synchronous transmission between processes

memory management
  • for an executing process
  • protection of the private address space of a process
  • memory management(swapping entire process, when suspended and paging part of process memory)by writing process memory to secondary memory
Internal structure of process (user context and kernel context)
User Context
  text segment
  • instructions of the program
  data segment
  • intialized data (globals) and unintialized data
  stack segment
  • Temporary data storage in kernel, for storing local variables, function parameters, and pointer to the previous stack frame for function call
  • kernel and user stacks are separate, depending on the execution mode(kernel or user)
  heap segment
  • dynamically allocated spcae by the process during execution
Kernel context
  • information needed by the kernel to do process management
  • used when the process runs in system mode
key process attributes
  • processID,parent process ID,process group ID, user and group ID(real, user/group ID of the user who invoked the process)(effective, UID and GID to run the process as the program owner),process priority  

Creation of process in Unix
  • process 0(swapper) is created by system at booti time
  • process 1 (init,user space) is created by swapper, and is the parent of all other processes
  • fork() is used to create a new process, and the process calling it is the parent and the new process created dur to fork() is the child process
  • the child process is created with copy of text and data segment of the parent, and by using an exec() the child can overlay the current process with a new program 
  • fork() returns two values 0 to the child process and processid of the child to the parnet process
  • a process can have only one parent but many childs

orphaned process
  • when the parent exits befor the child exits
  • orphaned process are adopted by init, thus the parent process id is 1
  • init does a wait on the orpahaned child process, cleanup the process table on exit of the child
zombie process
  • child process exist but the entry in the process table is still there
  • parent in notified with a SIGCHILD
  • child remains in the zombie state till the parent does a wait and reads the exit status of the child
process states and priority (0 is the highest) (ps command)
  • running (R)
  • sleeping (S)
  • stopped (T)
  • zombie (Z)
  • priority can be modified using nice and renice commands
  • ps -l shows the following
  • process State(S),priority(PRI),nice value(NI)
the proc pseudo file system
  • no disk space is occupied by the proc file system
  • is an interface to the internal data structures of the kernel
  • contain process soecific sub directories  based on pid




No comments: