Question

In: Computer Science

What is a program? What is a process? What is a thread?


What is a program? What is a process? What is a thread? Explain the differences/similarities in details between them.

Solutions

Expert Solution

1. What is a Program: A program is a group of instructions which is created to perform a specific task on the computer. The program itself does not perform any action and it stored on any file or memory device.

Example: below is a program which will add a and b variables and print the sum which is stored in c variable:

Main(){

Int a =10, b= 20;

Int c;

Cout<<“Sum of a and b is “<

}

2. What is a Process: A process is an activity going on in the computer. The program to be executed needs a process or group of processes for its execution. When a process is started required data is moved from secondary storage to processor’s registers. A process needs Processor, Input/Output devices, memory to accomplish the goal. A process can be:

  • An executing program
  • Any unit of work scheduled by the operating system.
  • Any activity going on the system

Execution of the program means, that program is using the processor, accessing the other resources required, changing its variable values etc. Process understands what is being required in the program to be executed and perform the same actions. A program can have multiple processes in it.

Example: The process to execute the example program will have below characteristics:

  • Process ID: Unique ID of the process e.g.
  • Process State: State of the process to execute the program. It can be waiting, running, stopped, terminated.
  • Program Counter: The address of the next instruction in the process to be executed
  • Registers: The registers list which is to be used for the process to execute the program
  • Memory: Process will hold memory of processor which can be maim memory OR cache memory
  • Opened Files: The process will refer multiple files while execution

3. What is a Thread: Threads are the light weight processes OR sub-part of processes, which can be independently managed by the scheduler. The threads are part of processes. Each thread has its parent process and it belongs to exactly one process during its life time.

Example: To execute the above program in the processor, it will be divided into small threads to perform the independent task. E.g. Thread #1 will move the variables to the main memory, Thread #2 will make a space in memory to store variable c whereas another variable will calculate sum of a and b. The use of threads can be user defined as well as processor defined.

Below diagram shows the purpose and definition of Program, Purpose and Threads:

Similarities between Program, Process and Thread

From above definitions, it can be clearly defined that program, process and thread has same purpose, which is to perform the action required on the user’s input. The program tells what to do in a passive way; the process is created by the process to DO the actions in program. The process is divided into small threads to manage the processes in a better way.

The following figure depicts that how three aspects are used together to make the computer functioning correctly and provide the results for the user input.

Difference between Program, Process and Thread

Although the program, process and threads work with each other to achieve the result for the end user yet all terms has certain differences among functionality, lifetime and behaviour. Please find below the differences between the same:

Feature Program Process Thread
Mode It a ordered instuctions in passive mode. Program instance in active mode is called process Threads have the active mode
Dependency It does not depends on process or thread. Process depends on the instuctions in program Threads depends on the parent process
Lifespan It has longer lifespan as compared to process and thread. The program needs to be deleted by the user manually. Process has longer lifespan than thread but smaller lifespan than program Threads have smallest lifespan
Memory It needs only a file space in memory. The file stores the instructions in it Needs independent CPU memory and dedicated registers. Doesn't has own memory, share the process's memory
Purpose Tell the computer what to do. Execute the action defined in 'What to do' Help process to perform action in faster and better way
Input Output devices The program does not need input output devices for execution. Process needs dedicated input and output devices for executing the process. Threads use parent process's input output devices
System Calls System calls are not needed. System calls are needed in various stages of the process. System calls are not needed.
Memory sharing It does not shared the memory Processes do not share the memory. Threads shares the memory with each other.
Existence A program can exist individually Process can exist individually for a program Threads can not exist individually, these are created and destroyed within a process
Instances Program can have different instances of processes. Whenever s program is executed a separated process is created. Process has its life cycle, where it starts, executes and ends as per instructions. Threads are the small instances of process which starts and ends within the life of parent process.

Related Solutions

Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program...
Thread Programming (C Programming) Objective Develop threads: thread and main. Functionality of Threads: The main program accepts inputs from the user from the console. The user can provide the following two types of input: add num1 num2 mult num1 num2 Here, num1 and num2 are two integer numbers. E.g., the user may input add 1 2. The threads receive the command along with the number, and performs the appropriate arithmetic operation and returns the results to main program. The main...
Thread: DQ1: Discuss the decision-making process in the textbook.
Thread: DQ1: Discuss the decision-making process in the textbook.
Process & Thread Management differences in Windows10, Linux, and Andriod.
Process & Thread Management differences in Windows10, Linux, and Andriod.
If bolt thread length is normally distributed, what is the probability that the thread length of...
If bolt thread length is normally distributed, what is the probability that the thread length of a randomly selected bolt is (a) Within 1.3 SDs of its mean value? (b) Farther than 1.5 SDs from its mean value? (c) Between 1 and 2 SDs from its mean value? You may need to use the appropriate table in the Appendix of Tables to answer this question.
If bolt thread length is normally distributed, what is the probability that the thread length of...
If bolt thread length is normally distributed, what is the probability that the thread length of a randomly selected bolt is (a) Within 1.3 SDs of its mean value? (b) Farther than 2.1 SDs from its mean value? (c) Between 1 and 2 SDs from its mean value?
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread...
DO THIS IN JAVA Write a complete Java program. the program has two threads. One thread prints all capital letters 'A' to'Z'. The other thread prints all odd numbers from 1 to 21.
1. Why there needs to be user thread and kernel thread? 2. What are the advantages...
1. Why there needs to be user thread and kernel thread? 2. What are the advantages and disadvantages of writing an operating system in a highlevel language, such as C? 3. What is a critical section problem? Demonstrate that with an example. 4. With an example, show how critical section can led to dead locks. 5. Write two differences between a network OS and a distributed OS. 6. Identify the following environments as hard, firm or soft real time. Give...
You will be writing a C program to test the data sharing ability of a thread...
You will be writing a C program to test the data sharing ability of a thread and process. Your C program will do the following: 1. Your parent program will have three variables: int x,y,z; which to be initialized as 10, 20, and 0, respectively. 2. parent creating child: parent will create a child by fork() and the child will perform z = x+y (i.e., add x and y and store the results in z). parent will wait for child...
Does the following describe a "thread" or a "process"? Fill in the blank. Considered a heavyweight...
Does the following describe a "thread" or a "process"? Fill in the blank. Considered a heavyweight operation Does the following describe a "thread" or a "process"? Fill in the blank. Context switching is less expensive
Write a C program that creates 5 threads sends the thread index as an argument to...
Write a C program that creates 5 threads sends the thread index as an argument to the thread execution procedure/function. Also, the main process/thread joins the newly created threads sequentially one after the other. From the thread procedure print “I am a thread and my index is “ [print the correct index number]. From the main thread after the join print “I am the main thread and just completed joining thread index “ [print the correct index].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT