Program, Process and Threads

  • by

PROGRAM

The definition of program is linked to the definition of algorithm. An algorithm is a sequence of finite steps which can be executed mechanically to solve a problem. The key points are that algorithms are self-contained; the steps given are sufficient to solve the problem at hand. No additional information is required. Also, the steps are finite; an algorithm must terminate. If it is case of steps going on for ever with some hope of getting the result, it is not an algorithm.

An algorithm coded in a programming language like C is a program. All programs have a starting point, the first instruction to be executed. In C language, a program's execution starts with the main function. There can only be one starting point in a program. That is, there is only one main function in a C Program. A program contains the instructions and data required to solve a problem.

PROCESS

In order to execute a program, the operating system kernel running on a computer has to create a process. A process is an execution environment in a computer system for solving a problem. A process has an id, called process-id. It has other attributes like the parent process id, the process which created this process. Some other attributes are user and group ids of the user who is the owner of the process, the execution times, etc. The Linux command ps gives the attributes of the processes running on the system. Most importantly, a process has an address space in the computer's virtual memory, which has the code segment (also called text segment), containing the program instructions, and the user data segment, containing the heap and the stack. The code and data segments of a process are initialized from the program, which is the only relationship between a process and the program. A process can initialize its code and data segments from different programs at different times and can execute multiple programs during its lifetime. It executes one program at a time and, and mostly, one program in its lifetime. The attributes of a process are kept separately in the system data segment for the process, which is outside the process's address space and, hence can not be modified by the process and can only be modified by the kernel.

On a Linux system, a process is created using the fork system call. A previously running process executes the fork system call and the result is a clone of the process that executed fork. So we have two processes, a parent process that executed the fork system call and a newly born child process that is (almost) a copy of the parent. In order to execute a particular program, the child process executes the exec system call, using the file name of the program as a parameter. exec initializes the process's code and data segments from the given program and the program execution starts. exec is, in fact, a family of six system calls, execl, execv, execlp, execvp, execle and execve. After exec, there is really no relationship between the program and the process. Any number of processes may initialize their code and data segments from the same program using exec and execute the program.

THREADS

By default, a processes has a single thread of execution. It is possible to have multiple threads of execution in a process. Or, in other words, we can have multiple threads in a process. Each thread has a starting function in the process's code segment. All threads share the process's code and global data. Threads are normally supported by the pthreads library.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You may like these, also

  • POSIX message queues in LinuxPOSIX message queues in Linux 1.0 POSIX Message queues POSIX interprocess comunication (IPC) was introduced in the POSIX.1b standard (IEEE Std 1003.1b-1993) for real time…
  • POSIX Shared Memory in LinuxPOSIX Shared Memory in Linux 1.0 Shared Memory Shared memory is the fastest method of interprocess communication (IPC) under Linux and other Unix-like systems. The…
  • POSIX Semaphores in LinuxPOSIX Semaphores in Linux 1.0 Semaphores Semaphores are used for process and thread synchronization. Semaphores are clubbed with message queues and shared memory under…
  • fork and exec system calls in Linuxfork and exec system calls in Linux 1.0 fork and exec system calls Suppose we wish to write a "shell program" which would execute another program. Now,…
  • Connecting two computers with Ethernet LAN cableConnecting two computers with Ethernet LAN cable Quite often, we wish to connect two computers back to back using an Ethernet LAN cable. It may be because…
  • D-Bus TutorialD-Bus Tutorial 1.0 D-Bus D-Bus is a mechanism for interprocess communication under Linux and other Unix-like systems. D-Bus has a layered architecture.…
  • Socket programming using the select system callSocket programming using the select system call 1.0 Client-Server Paradigm The Client-Server paradigm divides the software architecture of a system in two parts, the server and its…
  • System V message queues in LinuxSystem V message queues in Linux 1.0 Message queues Message queues are one of the interprocess communication mechanisms available under Linux. Message queues, shared memory and…
  • POSIX Threads Synchronization in CPOSIX Threads Synchronization in C 1.0 POSIX Threads Synchronization POSIX Threads provide multiple flows of execution within a process. The threads have their own stacks…
  • System V Shared Memory in LinuxSystem V Shared Memory in Linux 1.0 Shared Memory Shared memory is one of the three interprocess communication (IPC) mechanisms available under Linux and other Unix-like…