Linux Questions
Linux Questions
Linux
2) What is a process?
A process is an instance/object of a program that is being executed. While a program the actual code, a process is the execution of that code.
Several processes may be associated with the same program; for example, opening up several instances of the same program often results in more
than one process being executed.
4) Process states?
a. Spawn – Memory allocation
b. Waiting –
i. Interruptible sleep mode- In this mode process awaits for particular time slot or specific event to occur. If those
conditions occur, then process will come out of sleep mode. These processes are shown with
state S in ps or top output.
ii. Uninterruptible sleep mode- Process in this sleep mode gets its timeout value before going to sleep. Once the
timeout sets off, it awakes. Or it awakes when waited-upon resources becomes available for it. It can be
identified by state D in outputs.
c. Runnable - Runnable state is when process has got all the system resources to perform its operation except CPU. This
means process is ready to go once CPU is free. Runnable processes are also flagged with state flag R
d. Running - Most healthy state of all. It indicates process is active and serving its requests. Process is properly getting system
resources (especially CPU) to perform its operations. Running process is process which is being served by CPU currently.
It can be identified by state flag R in ps or top output.
e. Stopped - Process ends or terminates when they receive kill signal or they enter exit status. At this moment, process gives
up all the occupied resources but does not release entry in process table. Instead it sends signal about termination to its
parent process. This helps parent process to decide if child is exited successfully or not. Once SIGCHLD received by
parent process, it takes action and release child process entry in process table.
f. Zombie - While exiting process sends SIGCHLD to parent. During the time between sending signal to parent and then
parent clearing out process slot in process table, process enters zombie mode. Process can stay in zombie mode if its parent
died before it releases child process’s slot in process table. It can be identified with Z in outputs.
7) Orphan process?
Child process becomes orphan process if parent dies before child’s execution completes. Ideally parent should wait till child’s execution
completes and it is gracefully killed.
8) Difference between primary memory and secondary memory?
Primary memory is the main memory which is directly accessible by CPU using data bus and has the current processing data. However,
secondary memory is where data is stored for a longer time, is accessible by I/o channels and cannot be accessed by CPU directly.
The primary benefits of virtual memory include freeing applications from having to manage a shared memory space as the program data is stored
in different blocks in the memory with a pointer to them present in the registers, increased security due to memory isolation, and being able to
conceptually use more memory than might be physically available, using the technique of paging.
11) What manages the address translation from virtual to physical memory?
Address translation hardware in the CPU, often referred to as a memory management unit or MMU, automatically translates virtual addresses to
physical addresses. Software within the operating system may extend these capabilities to provide a virtual address space that can exceed the
capacity of real memory and thus reference more memory than is physically present in the computer.
Locality of reference is basically a name given to the phenomenon in which the nearby/related data of a data is also swapped into the memory
when a particular data is requested by CPU considering that the CPU might ask for the nearby data frequently. Anticipatory paging is based on
this.
15) 4gb ram + 4 gb hdd, application of 10gb, what will be the end result?
For virtual memory concept also, application needs to be accommodated in the secondary memory. So, we need a bigger secondary memory for
this.
a) Long-Term Scheduler: It selects processes from the queue and loads them into memory for execution. Process loads into
the memory for CPU scheduling.
b) Short-Term Scheduler: CPU scheduler selects a process among the processes that are ready to execute and allocates CPU
to one of them.
c) Medium-Term Scheduler: It is a part of swapping. It removes the process from memory. The medium-term scheduler is in-
charge of handling the swapped out-processes. Execution is saved in case of swap out/in.
b) Ready queue − This queue keeps a set of all processes residing in main memory, ready and waiting to execute. A new
process is always put in this queue.
c) Device queues − The processes which are blocked due to unavailability of an I/O device constitute this queue.
25) Let’s say you have two computers (same hardware with single core): one is single thread and other is multi-thread-- which one is faster?
Single-thread, as multi thread will have context switching delays.
26) For a multi core environment, which is faster, single threaded application or multi-threaded application with each application doing
independent arithmetic?
Multi-threaded as threads can be divided among the cores and execution will be faster.
e) Tcpdump: Can use tcpdump to analyze packet captures to see if TCP connection established, SSL established, what was
HTTP request, what was the response. If there were any retransmits, what was the window size, etc.