EmbLogic's Blog

   

            What are  processes and threads??


  • A process is a program (object code stored on some media) in execution.
  •  Processes are, however, more than just the executing program code (often called the text section in Unix). They also include a set of resources such as open files and pending signals, internal kernel data, processor state, an address space, one or more threads of execution, and a data section containing global variables. Processes, in effect, are the living result of running program code.
  • Threads of execution, often shortened to threads, are the objects of activity within the process.
  •  Each thread includes a unique program counter, process stack, and set of processor registers. The kernel schedules individual threads, not processes.
  •  In traditional Unix systems, each process consists of one thread. In modern systems, however, multithreaded programs those that consist of more than one thread are common.
  •  But,to Linux, a thread is just a special kind of process.
  • People generally are confused that a program is a process but a process is an active program and related resources. Indeed, two or more processes can exist that are executing the same program. In fact, two or more processes can exist that share various resources, such as open files or an address space.
  • A process begins its life when, not surprisingly, it is created. In Linux, this occurs by means of the fork() system call, which creates a new process by duplicating an existing one.
  • The new process is an exact copy of the old process. (Now, a question might come immediately to our mind- who creates the first process?? The first process is the init process which is literally created from scratch during booting).
  • The process that calls fork() is the parent, whereas the new process is the child. The parent resumes execution and the child starts execution at the same place, where the call returns. The fork() system call returns from the kernel twice: once in the parent process and again in the newborn child.
  • Often, immediately after a fork it is desirable to execute a new, different, program. The exec*() family of function calls is used to create a new address space and load a new program into it. In modern Linux kernels, fork() is actually implemented via the clone() system call,
  • Finally, a program exits via the exit() system call. This function terminates the process and frees all its resources.
  • A parent process can inquire about the status of a terminated child via the wait4()system call, which enables a process to wait for the termination of a specific process.
  •  When a process exits, it is placed into a special zombie state that is used to represent terminated processes until the parent calls wait() or waitpid().
  • The kernel implements the wait4() system call. Linux systems, via the C library, typically provide the wait(),waitpid(),wait3() , and wait4() functions. All these functions return status about a terminated process, albeit with slightly different semantics.
  • Another name for a process is a task.  although when we say task we generally mean a process from the kernel’s point of view

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>