0% found this document useful (0 votes)
4 views

Linux Questions

The document provides comprehensive information about operating system concepts, including processes, memory management, virtual memory, scheduling, and file systems. It explains various process states, types of memory, and the booting process, along with troubleshooting commands for networking and system performance issues. Additionally, it covers differences between multi-threading and multi-processing, context switching, and the impact of fragmentation on system performance.

Uploaded by

rogerfed027
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Linux Questions

The document provides comprehensive information about operating system concepts, including processes, memory management, virtual memory, scheduling, and file systems. It explains various process states, types of memory, and the booting process, along with troubleshooting commands for networking and system performance issues. Additionally, it covers differences between multi-threading and multi-processing, context switching, and the impact of fragmentation on system performance.

Uploaded by

rogerfed027
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1) Which OS you are most comfortable?

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.

3) How process is created?


Memory is allocated for the process. Executable code is loaded in that memory and then the process is 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.

g. Removed from process table

5) Which system call creates child process?


Fork() allocates memory and exec() executes it

6) What will happen if parent process dies?


If parent dies without child’s complete execution, child process becomes orphan, however, if parent dies after sigchild and before removing the
child from process table, child becomes zombie process.

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.

Primary memory is faster than secondary memory.

Primary memory would be RAM. Once power goes it will be erased.


Secondary will be hard disk, CD etc.

9) What is virtual memory?


Virtual Memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory. For
program, it’ll refer the virtual memory address for the required data. MMU then loads the page table and using the translation, finds the physical
address of the page. If page present then good, else page fault which is handled by swapping.

10) Why is virtual memory used?

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.

12) What is locality of reference in terms of memory?

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.

13) Mapping of virtual memory to physical memory?


Page table is used by MMU. Physical memory is divided into frames and page table is maintained for the location of each frame along with the
offset. CPU generates virtual address and using the page number in that, frame number is found for the physical memory and then the memory is
referenced.

14) How an 8gb program works on 4gb ram machine?


Program is stored as divided into pages in the secondary memory. CPU when asks for a particular byte, it generates a virtual address, which is
then converted to physical address. Data is fetched from that physical address. If data is there then it’s provided, else it’s a page fault and then
swap-in swap-out occurs. Hence, there is no need to keep the entire 8gb program in RAM. Rather, only some part is required to be there. Also,
not the entire 4gb ram is usable. Some of it is reserved for OS and only some of it is given to the user level programs.

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.

16) How to check physical and virtual memory?


Free/vmstat in linux shows swap memory which is the virtual memory space and mem, which is the physical memory space.
17) Page-fault?
If page requested is not in physical memory, it is fetched from the secondary storage

18) How is swapping diffrent from paging. Which is more efficient?


Paging: Only the required pages are swapped out/in
Swapping: Whole process is swapped out/in

19) What is on demand paging?


Page is loaded into main memory only when it’s referenced

20) Schedulers, its role?


Schedulers are special system software which handle process scheduling in various ways. Their main task is to select the jobs to be submitted
into the system and to decide which process to run. Schedulers are of three types −

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.

21) How many types of process scheduling queues are there?


The OS maintains a separate queue for each of the process states and PCBs of all processes in the same execution state are placed in the same
queue.
a) Job queue − This queue keeps all the processes in the system.

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.

22) Scheduling tasks in OS, allocate memory:


i) Fcfs: First come first serve: Process which comes first will be served first entirely
ii) SJF: Shortest job first:
a) Non-preemptive: Current shortest process is executed first and later arriving shorter processes will
have to wait. Problems: Starvation. Solved by aging.
b) Preemptive: As soon as a smaller process arrives, it is executed first.
iii) Priority: Each process has priority and the processes are executed in the order of their priority.
iv) Round-robin: A time is set and the process executes for that much time only before getting preempted.
v) Multi-level queue: Multiple queues are present and processes in each are processed according to a priority and each
queue can follow different algo.
vi) Multilevel feedback queue: Every queue has their own algo and priority but processes can switch queues based on
factors like wait time etc.

23) Multi-thread VS multi-process?


multi-process-- multiple process executes simultaneously
multi-thread-- a single process has multiple threads, all executes at same time independently
24) What is Pre-emption?
Depending on various algorithms, if CPU resources are taken from a process and given to some other, i.e., execution of a process is stopped and
other process starts executing.

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.

27) What is context switch?


It is the switching between processes/threads for the CPU cores. The current execution state is saved and then the CPU resources are given to
some other process. Once the other process completes, resources are again given to old process and execution continues. Most common example
is round robin scheduling.

28) On which level does context-switching works?


The context switching takes the access from user level and gives to it kernel level to switch the resources to some other process. In case of page
faults, context switching occurs and then kernel pulls the page from the secondary memory, pushes it to main memory and then again give the
control to user.

29) What is FileSystem and why do we need it?


A file system controls how data is stored and retrieved. Without a file system, information placed in a storage medium would be one large body
of data with no way to tell where one piece of information stops and the next begins. By separating the data into pieces and giving each piece a
name, the information is easily isolated and identified. The structure and logic rules used to manage the groups of information and their names is
called a "file system".

30) How system locate files?


Unix has a family tree and using the metadata in that file tree, a file is found.

31) Diff types of disk file system?


Disk file systems: FAT, exFAT, ext3, ext4, XFS, UDF, ISO 9660

32) How fragmentation impacts system?


Fragmentation in most cases wastes the memory. It increases the work required in memory allocation causing degradation. 3 types of
fragmentations:
a) Internal: Due to the rules governing memory allocation, sometimes, more memory is allocated than required. 29 bytes program might
get 32 bytes memory. Wasted memory cannot be claimed. Can be correct by dynamic memory allocation.
b) External: If a middle block is freed by the program and memory allocation skips that block if program requires more memory than
that. To overcome this, free memory blocks should be contagious.
c) Data: Occurs when file is pushed into the blocks created by external fragmentation. Has 4 algorithms to overcome:
a. Best fit: Chooses the smallest block which is big enough
b. Worst fit: Chooses the largest block
c. First fit: Chooses the first block which is big enough
d. Next fit: Modified version of first fit. It looks on from the point where last block was filled by first fit.
33) Booting process?
a) POST power on self-test which is a part of BIOS: Checks operability of hardware
b) BIOS (basic input output system): Searches and loads MBR and gives control to that.
c) MBR: Master boot record: Located in first sector of bootable disk. Loads and executes GRUB
d) GRUB: Grand unified bootloader: Grub loads and executes kernel and initrd images. Has 3 stages:
a. Stage 1: Primary boot loader takes upto less than 512 bytes of MBR. Requires more, hence passes on to stage 1.5
b. Stage 1.5: Located in first 30KB after MBR and before the first partition. Used to store file system drivers and modules.
Passes on to stage 2.
c. Stage 2: Responsible for loading kernel from /boot/grub/grub.conf
e) Kernel: Mounts root file system as specified in grub.conf. Executes init program. Initrd is Initial ram disk which is used by kernel as a
temporary file system till it boots and use the real file system
f) Init: Looks at /etc/inittab to decide linux run level. Identifies the default run level and uses it load the programs.
g) Runlevel programs: Programs configured to run on boot depending on run level.

34) Where is partition table stored?


Partition table is stored in MBR. Primary boot loader is 446 bytes, partition table info in next 64 bytes and mbr validation checks in last 2 bytes.

35) What is a niceness and how it impacts process execution?


It is basically a priority given to a process, thus giving a process more or less CPU time compared to other processes. A niceness of -20 is highest
priority and 19 is lowest. Default niceness is usually 0. Can be set using the command “nice -n 19 command”

36) What commands to use for troubleshooting a networking issue:


a) Dig: dig domain name. Used with +trace to check the name servers. Used with flags like CNAME, A, AAAA
for checking only certain type or records.
b) Curl: curl domain name. Used mostly with flags -IvLk to silent the actual website content, know the headers,
bypass invalid certificates and intelligent redirection. Header information can be used to troubleshoot
cookie/stickiness maintainence issues.
c) Logs of the web server: Apache/nginx application level logs are very helpful in finding the root causes of issues
along with the actual status codes provided.
d) Netstat: sudo netstat. Mostly used with -natpl to show all sockets with the hosts in IP format, display the tcp
states, displays PIDs and program names of the programs and also displays listening sockets.

37) What commands to use for troubleshooting network performance:


a) hping3: hping3 -c 10 -V <Private/Public IP of EC2 instance or On-Prem host> -S -p 80
b) tcp traceroute: traceroute -T -p 80 <Private/Public IP of EC2 instance or On-Prem host>
c) tcp mtr: mtr -n -T -c 200 <Private/Public IP of EC2 instance or On-Prem host> --report
d) iperf3: iperf3 -s -V on server and iperf3 -c <Private/Public IP of EC2 instance or On-Prem host> -P 10 -t 30 on client for
10 parallel streams.

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.

38) What commands to use to troubleshoot system performance issues:


a) Top: sudo top: will show CPU as well as memory util along with the util of every process.
b) Free: sudo free: Will show the memory statistics in detail
c) Vmstat: Used to monitor memory, usually swap/virtual memory. Can use vmstat 1 to refresh it every second for real time
monitoring
d) Ps: ps aux: Shows details of all the processes and their respective utilizations
e) Iostat: Installed by running yum install sysstat: Shows all the IO information along with CPU information.

39) How to kill a process?


Using the command “kill pid”. PID can be found by running “ps aux”.

You might also like