Linux software application development online tests

Module: Linux process, thread

Advertisements

 | 

You will learn about all the interview questions asked on linux process, thread through this online test. Click to start this online test.


Frequently asked questions


Process, Thread, Difference between processes and threads

What is a process?
    A process is an active program i.e. a program that is under execution. It is more than the program code as it includes the program counter, process stack, registers, program code etc. Compared to this, the program code is only the text section.

What is a Thread?
    A thread is a lightweight process that can be managed independently by a scheduler. It improves the application performance using parallelism.

Difference between processes and threads
    Following are the difference between a linux process and thread.

  • A process is a program under execution i.e an active program. A thread is a lightweight process that can be managed independently by a scheduler.
  • Processes require more time for context switching as they are more heavy. Threads require less time for context switching as they are lighter than processes.
  • Processes are totally independent and don’t share memory. A thread may share some memory with its peer threads.
  • Communication between processes requires more time than between threads. Communication between threads requires less time than between processes.
  • If a process gets blocked, remaining processes can continue execution. If a user level thread gets blocked, all of its peer threads also get blocked.
  • Processes require more resources than threads. Threads generally need less resources than processes.
  • Individual processes are independent of each other. Threads are parts of a process and so are dependent.
  • Processes have independent data and code segments. A thread shares the data segment, code segment, files etc. with its peer threads.
  • All the different processes are treated separately by the operating system. All user level peer threads are treated as a single task by the operating system.
  • Processes require more time for creation and termination. Threads require less time for creation and termination.
  • Process, Background process example illustration

    Process example
        To illustrate process creation, let's write a program Listing1.c as shown below.
    
    /*
    * Listing1.c Program to illustrate process creation
    */
    #include 
    int main()
    {
      while(1);
      return 0;
    }
    
        The output of the above program is shown below. We have run the executable Listing1. Now lets's see if the process is available in the list of processes in the system. Open another terminal and execute command "ps -ax | grep Listing1" to see the list of processes running on the system. You will find that ./Listing1 process is listed there.
    $ gcc Listing1.c -o Listing1
    $ ./Listing1
    
        List of currently running processes are shown below.
    $ ps -ax | grep Listing1
     3795 pts/1    R+     0:34 ./Listing1
    $
    
    Background Process
         You can run a process in backgroung by appending & to the process as shown below.
    $ gcc Listing1.c -o Listing1
    $ ./Listing1 &
    
    $ ps -ax | grep Listing1
     3722 pts/1    R+     0:34 ./Listing1
    $
    

    Thread creation example illustration

    Thread creation example illustration

     | 
    Share

     Online Tests


    Linux software tests
    Related Online Tests