What is 'inode'?
What is the difference between Swapping and Paging?
What is a zombie?
inetd: Responsible for starting network services that do not have their own stand-alone daemons. For example, inetd usually takes care of incoming rlogin, telnet, and ftp connections.
cron: Responsible for running repetitive tasks on a regular schedule.
What is page fault?
Page fault refers to the situation of not having a page in the main memory when any process references it.
There are two types of page fault :
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of the pipe (producer) and the other reads from the other end (consumer).
How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the disk.
- All UNIX files have its description stored in a structure called 'inode'. The inode contains information about the file-size, location, time of last access, time of last modification, permission etc.
- Directories are also represented as files and have an associated inode.
- Inode holds pointers to the data blocks of the file. If the file is large, inode has indirect pointer to a block of pointers to additional data blocks .A block is typically 8k.
- Inode consists of the following fields:
- File owner identifier
- File type
- File access permissions
- File access times
- Number of links
- File size
- Location of the file data
How to kill a process?
The kill command takes the PID as one argument; this identifies which process to terminate. The PID of a process can obtained using 'ps' command.
Kill <pid>
kill -9 <pid>
Components of Operating Systems
Components of Operating Systems
- An operating system is a large and complex system that can only be created by partitioning into small pieces.
- Operating system shares the various OS system components like File, Process Memory, I/O device management, etc.
- A file is a collection of related information which is should define by its creator.
- The process management component is a procedure for managing the many processes that are running simultaneously on the operating system
- I/O device management is one of the important use of an operating system that helps you to hide the variations of specific hardware devices from the user.
- Network management is the process of administering and managing computer networks.
- The memory management process is conducted by using a sequence of reads or writes of certain memory addresses.
- Secondary-Storage Management, the most important task of a computer system, is to execute programs.
- Security management includes various processes in an operating system that need to be secured from each other's activities.
- The operating system checks the capability of the program to read, write, create, and delete files.
What is the difference between Swapping and Paging?
Swapping:
- Complete process is moved from the swap device to the main memory for execution.
- Process size must be <= available main memory.
- Swapping systems does not handle the memory more flexibly as compared to the paging systems.
- Only the required memory pages are moved to main memory from the swap device for execution.
- Process size does not matter. Uses the concept of the virtual memory.
- It provides greater flexibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more flexibly.
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls `wait()'; In the interval between the child terminating and the parent calling `wait()', the child is said to be a `zombie' (If you do `ps', the child will have a `Z' in its status field to indicate this.)
What are the process states in Unix?
As a process executes it changes state according to its conditions. Unix processes have the following states:
- Running : The process is either running or it is ready to run .
- Waiting : The process is waiting for an event or for a resource.
- Stopped : The process has been stopped, usually by receiving a signal.
- Zombie : The process is dead but have not been removed from the process table.
What are links and symbolic links in UNIX file system?
- A link is a second name (not a file) for a file. Links can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers.
- Symbolic link 'is' a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.Both the limitations of links are eliminated in symbolic links.
Commands for linking files are:
Link ln filename1 filename2
Symbolic link ln -s filename1 filename2
How to identify commands in linux?
1)type -- Display a Command's Type
[@linux ~]$ type cp
cp is /bin/cp
[@linux ~]$ type ls
ls is aliased to `ls --color=tty'
2)which -- Display an Executable's Location
[me@linuxbox ~]$ which ls
/bin/ls
1)type -- Display a Command's Type
- The type command is a shell builtin that displays the kind of command the shell will execute, given a particular command name
- Syntax : type command
[@linux ~]$ type cp
cp is /bin/cp
[@linux ~]$ type ls
ls is aliased to `ls --color=tty'
2)which -- Display an Executable's Location
- To determine the exact location of the given executable which command is used.
- which works only for executable programs, not builtins or aliases that are substitutes for actual executable programs
[me@linuxbox ~]$ which ls
/bin/ls
How can a parent and child process communicate?
A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.
What is System Call in Operating System?
A system call is a mechanism that provides the interface between a process and the operating system. It is a programmatic method in which a computer program requests a service from the kernel of the OS.
System call offers the services of the operating system to the user programs via API (Application Programming Interface). System calls are the only entry points for the kernel system.
How System Call Works?
Step 1) The processes executed in the user mode till the time a system call interrupts it.
Step 2) After that, the system call is executed in the kernel-mode on a priority basis.
Step 3) Once system call execution is over, control returns to the user mode.,
Step 4) The execution of user processes resumed in Kernel mode.
Why do you need System Calls in OS?Types of System calls ?
Following are situations which need system calls in OS:
- Reading and writing from files demand system calls.
- If a file system wants to create or delete files, system calls are required.
- System calls are used for the creation and management of new processes.
- Network connections need system calls for sending and receiving packets.
- Access to hardware devices like scanner, printer, need a system call.
Here are the five types of system calls used in OS:
- Process Control
- File Management
- Device Management
- Information Maintenance
- Communications
Categories | Windows | Unix |
---|---|---|
Process control | CreateProcess() ExitProcess() WaitForSingleObject() | fork() exit() wait() |
Device manipulation | SetConsoleMode() ReadConsole() WriteConsole() | loctl() read() write() |
File manipulation | CreateFile() ReadFile() WriteFile() CloseHandle() | Open() Read() write() close!) |
Information maintanence | GetCurrentProcessID() SetTimer() Sleep() | getpid() alarm() sleep() |
Communication | CreatePipe() CreateFileMapping() MapViewOfFile() | Pipe() shm_open() mmap() |
Protection | SetFileSecurity() InitlializeSecurityDescriptor() SetSecurityDescriptorGroup () | Chmod() Umask() Chown() |
What is a Daemon?
- A daemon is a process that detaches itself from the terminal and runs, disconnected, in the background, waiting for requests and responding to them. It can also be defined as the background process that does not belong to a terminal session.
- Many system functions are commonly performed by daemons, including the sendmail daemon, which handles mail, and the NNTP daemon, which handles USENET news. Many other daemons may exist. Some of the most common daemons are:
inetd: Responsible for starting network services that do not have their own stand-alone daemons. For example, inetd usually takes care of incoming rlogin, telnet, and ftp connections.
cron: Responsible for running repetitive tasks on a regular schedule.
What is page fault?
Page fault refers to the situation of not having a page in the main memory when any process references it.
There are two types of page fault :
- Validity fault
- Protection fault.
FIFO are otherwise called as 'named pipes'. FIFO (first-in-first-out) is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. It is used in interprocess communication where a process writes to one end of the pipe (producer) and the other reads from the other end (consumer).
How do you create special files like named pipes and device files?
The system call mknod creates special files in the following sequence.
1. kernel assigns new inode,
2. sets the file type to indicate that the file is a pipe, directory or special file,
3. If it is a device file, it makes the other entries like major, minor device numbers.
For example:
If the device is a disk, major device number refers to the disk controller and minor device number is the disk.
Can I use a named pipe across NFS?
No, you can't. There is no facility in the NFS protocol to do this.
What is File System?
A file is a collection of correlated information which is recorded on secondary or non-volatile storage like magnetic disks, optical disks, and tapes. It is a method of data collection that is used as a medium for giving input and receiving output from that program.
In general, a file is a sequence of bits, bytes, or records whose meaning is defined by the file creator and user. Every File has a logical location where they are located for storage and retrieval.
File types- name, extension
File Type | Usual extension | Function |
Executable | exe, com, bin or none | ready-to-run machine- language program |
Object | obj, o | complied, machine language, not linked |
Source code | c. p, pas, 177, asm, a | source code in various languages |
Batch | bat, sh | Series of commands to be executed |
Text | txt, doc | textual data documents |
Word processor | doc,docs, tex, rrf, etc. | various word-processor formats |
Library | lib, h | libraries of routines |
Archive | arc, zip, tar | related files grouped into one file, sometimes compressed. |
What do you understand by umask ?
umask is abbreviated for ‘User file creation mask’, that is used to determine the settings of a mask that controls file permissions that are set for files and directories when they are created.
How will you set the umask permanently for a user?
In order to set this value permanently for a user, it has to be put in the appropriate profile file that depends on the default shell of the user.
How can you change the default run level in linux ?
In order to change the run level we have to edit the file “/etc/inittab” and change initdefault entry ( id:5:initdefault:). Using ‘init’ command we change the run level temporary like ‘init 3’ , this command will move the system in runlevl 3.
How will you check default route and routing table ?
We can check default route and routing table using the Commands ‘netstat -nr’ and ‘route -n’
What is Memory Leak?
- Memory is allocated on demand—using malloc() or one of its variants—and memory is freed when it’s no longer needed.
- A memory leak occurs when memory is allocated but not freed when it is no longer needed.
- Leaks can obviously be caused by a malloc() without a corresponding free(), but leaks can also be inadvertently caused if a pointer to dynamically allocated memory is deleted, lost, or overwritten.
- Buffer overruns—caused by writing past the end of a block of allocated memory—frequently corrupt memory.
- Memory leakage is by no means unique to embedded systems, but it becomes an issue partly because targets don't have much memory in the first place and partly because they often run for long periods of time without rebooting, allowing the leaks to become a large puddle.
- Regardless of the root cause, memory management errors can have unexpected, even devastating effects on application and system behavior.
- With dwindling available memory, processes and entire systems can grind to a halt, while corrupted memory often leads to spurious crashes.
What is CPU Scheduling?
CPU Scheduling is a process of determining which process will own CPU for execution while another process is on hold. The main task of CPU scheduling is to make sure that whenever the CPU remains idle, the OS at least select one of the processes available in the ready queue for execution. The selection process will be carried out by the CPU scheduler. It selects one of the processes in memory that are ready for execution.
Types of CPU scheduling Algorithm
There are mainly six types of process scheduling algorithms
- First Come First Serve (FCFS) - the process which requests the CPU gets the CPU allocation first.
- Shortest-Job-First (SJF) Scheduling - the shortest execution time should be selected for execution next
- Shortest Remaining Time - the process will be allocated to the task, which is closest to its completion.
- Priority Scheduling - the scheduler selects the tasks to work as per the priority.
- Round Robin Scheduling - works on principle, where each person gets an equal share of something in turn
- Multilevel Queue Scheduling - method separates the ready queue into various separate queues. In this method, processes are assigned to a queue based on a specific property
The Purpose of a Scheduling algorithm
Here are the reasons for using a scheduling algorithm:
- The CPU uses scheduling to improve its efficiency.
- It helps you to allocate resources among competing processes.
- The maximum utilization of CPU can be obtained with multi-programming.
- The processes which are to be executed are in ready queue.
Notes:
- CPU scheduling is a process of determining which process will own CPU for execution while another process is on hold.
- In Preemptive Scheduling, the tasks are mostly assigned with their priorities.
- In the Non-preemptive scheduling method, the CPU has been allocated to a specific process.
- Burst time is a time required for the process to complete execution. It is also called running time.
- CPU utilization is the main task in which the operating system needs to make sure that CPU remains as busy as possible
- The number of processes that finish their execution per unit time is known Throughput.
- Waiting time is an amount that specific process needs to wait in the ready queue.
- It is an amount to time in which the request was submitted until the first response is produced.
- Turnaround time is an amount of time to execute a specific process.
- Timer interruption is a method that is closely related to preemption,
- The CPU uses scheduling to improve its efficiency.
How to detect memory leak on Linux?
1) Valgrind memcheck
Valgrind is a powerful tool that rewrites the object code of the application as it is executed to allow the detection of many sorts of memory errors, including such things as out-of-bounds writes and use of unitialized memory. One of the side-capabilities of Valgrind is the ability to detect leaked memory blocks by conservatively scanning memory.
The above checks help with errors in memory access and usage, but errors related to unfreed resources (resource leaks) will go undetected. If you suspect a resoorce leak, it is time to get out the big guns.
Memcheck is the default tool when running valgrind, and will detect a nmber of problems that can occur in C and C++ programs:
- Accessing memory you shouldn't, e.g. overrunning and underrunning heap blocks, overrunning the top of the stack, and accessing memory after it has been freed.
- Using undefined values, i.e. values that have not been initialised, or that have been derived from other undefined values.
- Incorrect freeing of heap memory, such as double-freeing heap blocks, or mismatched use of malloc/new/new[] versus free/delete/delete[]
- Overlapping source and destination pointers in memcpy and related functions.
- Passing a negative value to the size parameter of a memory allocation function.
- Memory leaks.
% valgrind --leak-check=full ./a.out<br />
==8110== Memcheck, a memory error detector<br />
==8110== Copyright (C) 2002-2015, and GNU GPL d, by Julian Seward et al.<br />
==8110== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info<br />
==8110== Command: ./a.out<br />
==8110== Hello, world!<br />
==8110==<br />
==8110== HEAP SUMMARY:<br />
==8110== in use at exit: 56 bytes in 2 blocks<br />
==8110== total heap usage: 4 allocs, 2 frees, 73,784 bytes allocated<br />
==8110==<br />
2) MemProf
- MemProf is a memory leak detector and profiler that works in a somewhat similar fashion to Debauch. It's notable feature is a nice graphical front end. MemProf works only on Linux. memprof is a tool for profiling memory usage and finding memory leaks. It can generate a profile how much memory was allocated by each function in your program. Also, it can scan memory and find blocks that you’ve allocated but are no longer referenced anywhere.
- memprof works by pre-loading a library to override the C library’s memory allocation functions and does not require you to recompile your program.
3) ElectricFence
- ElectricFence catches buffer overruns by guarding each block of memory with write-protected pages.
- Electric Fence is another drop in replacement memory allocation library. It uses the virtual memory hardware of your computer to place an inaccessible memory page immediately after or before each memory allocation. This will generally cause your program to immediately seg fault if it attempts to read or write outside of the range of allocated memory. To use it, link your program with the efence library (e.g. with the -lefence linker option) or set the LD_codeLOAD environment variable to load the library when running your program.
4) Memwatch
This is another memory leak and allocation tool. I haven't tried it, and it hasn't been touched since 2003, so I'm skeptical that it works on current systems but you may want to give it a try. See http://www.linkdata.se/sourcecode/memwatch/
5) DMalloc
DMalloc is a very portable replacement for the C libraries memory allocation routines with a wide range of facilities for debugging and gathering statistics.
6) Dbgmem
- Dbgmem is a memory debugger for C and C++ programs on Linux systems. It can help track down memory leaks, heap memory corruption, stack corruption and use of freed or uninitialized heap memory. It works by overriding the Glibc memory allocation, memory and string manipulation functions. I haven't personally used it, but it looks interesting. More details can be found at http://dbgmem.sourceforge.net/
- Dmalloc or Debug Malloc Library is a drop in replacement for the system's malloc and other memory management functions. It includes facilities for debugging errors and memory leaks. It runs on most operating system platforms.
7) Sar
The System Activity Reporter, or sar command, displays the contents of selected cumulative activity counters in the operating system. Information is reported on the paging system, i/o, CPUs, network interfaces, swap space, file system, and others. Here is a portion of the output when run with the -A option to display all output, and specifying an interval of one second and a count of one:
% sar -A 1 1<br />
Linux 4.10.0-35-generic (xpslaptop) 2017-09-19 _x86_64_ (8 CPU)<br />
04:37:21 PM CPU %usr %nice %sys %iowait %steal %irq %soft %guest %gnice %idle<br />
04:37:22 PM all 11.67 0.00 2.13 0.00 0.00 0.00 0.13 0.00 0.00 86.07<br />
04:37:21 PM proc/s cswch/s 04:37:22 PM 4.00 7568.00<br />
04:37:21 PM INTR intr/s 04:37:22 PM sum 1265.00<br />
04:37:21 PM CPU MHz<br />
04:37:22 PM all 899.93 04:37:22 PM 0 899.93<br />
04:37:22 PM 1 899.93 04:37:22 PM 2 899.93<br />
04:37:22 PM 3 899.93 04:37:21 PM TEMP degC %temp DEVICE<br />
04:37:22 PM 1 36.00 36.00 coretemp-isa-0000<br />
04:37:22 PM 2 34.00 34.00 coretemp-isa-0000<br />
04:37:22 PM 3 34.00 34.00 coretemp-isa-0000 Average: kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty kbanonpg kbslab kbkstack kbpgtbl kbvmused<br />
Average: 2926136 13341536 82.01 1448812 7238924 10483736 29.96 6586924 5648208 1444 3463220 723676 15728 85884 0
8) There are a number of standard Linux tools for looking at memory and resource usage that you should be familiar with
- df - report file system disk space usage
- dstat - versatile tool for generating system resource statistics
- du - estimate file space usage
- find - search for files in a directory hierarchy
- free - display amount of free and used memory in the system
- ifstat - report interface statistics
- iostat - report CPU statistics and input/output statistics for devices and partitions
- lsof - list open files
- memstat - identify what's using up virtual memory
- mpstat - report processors related statistics
- pmap - report memory map of a process
- ps - report a snapshot of the current processes
- top - display Linux processes
- vmstat - report virtual memory statistics
How can you assess Memory stats and CPU stats ?
We can assess memory stats and CPU stats using ‘free’ & ‘vmstat’ command that can be used display the physical and virtual memory statistics respectively. Also with the help of ‘sar’ command we see the CPU utilization & other stats.
Process vs Thread: What's the difference?
What is a Process?
A process is the execution of a program that allows you to perform the appropriate actions specified in a program. It can be defined as an execution unit where a program runs. The OS helps you to create, schedule, and terminates the processes which is used by CPU. The other processes created by the main process are called child process.
A process operations can be easily controlled with the help of PCB(Process Control Block). You can consider it as the brain of the process, which contains all the crucial information related to processing like process id, priority, state, and contents CPU register, etc.
What is Thread?
Thread is an execution unit that is part of a process. A process can have multiple threads, all executing at the same time. It is a unit of execution in concurrent programming. A thread is lightweight and can be managed independently by a scheduler. It helps you to improve the application performance using parallelism.
Parameter | Process | Thread |
---|---|---|
Definition | Process means a program is in execution. | Thread means a segment of a process. |
Lightweight | The process is not Lightweight. | Threads are Lightweight. |
Termination time | The process takes more time to terminate. | The thread takes less time to terminate. |
Creation time | It takes more time for creation. | It takes less time for creation. |
Communication | Communication between processes needs more time compared to thread. | Communication between threads requires less time compared to processes. |
Context switching time | It takes more time for context switching. | It takes less time for context switching. |
Resource | Process consume more resources. | Thread consume fewer resources. |
Treatment by OS | Different process are tread separately by OS. | All the level peer threads are treated as a single task by OS. |
Memory | The process is mostly isolated. | Threads share memory. |
Sharing | It does not share data | Threads share data with each other. |
What is Multithreading?
Multithreading refers to multiple threads of execution within an operating system. In simple terms, two or more threads of a same process are executing simultaneously.
Multithreading vs Multiprocessing: What's the difference?
What is Multiprocessing?
A multiprocessing system has more than two processors. The CPUs are added to the system that helps to increase the computing speed of the system. Every CPU has its own set of registers and main memory.
However, because each CPU are separate, it may happen that one CPU may not have anything to process. One processor may sit idle, and the other may be overloaded with the specific processes. In such a case, the process and resources are shared dynamically among the processors.
What is Multithreading?
Multithreading is a program execution technique that allows a single process to have multiple code segments (like threads). It also runs concurrently within the "context" of that process. Multi-threaded applications are applications that have two or more threads that run concurrently. Therefore, it is also known as concurrency.
Parameter | Multiprocessing | Multithreading |
---|---|---|
Basic | Multiprocessing helps you to increase computing power. | Multithreading helps you to create computing threads of a single process to increase computing power. |
Execution | It allows you to execute multiple processes concurrently. | Multiple threads of a single process are executed concurrently. |
CPU switching | In Multiprocessing, CPU has to switch between multiple programs so that it looks like that multiple programs are running simultaneously. | In multithreading, CPU has to switch between multiple threads to make it appear that all threads are running simultaneously. |
Creation | The creation of a process is slow and resource-specific. | The creation of a thread is economical in time and resource. |
Classification | Multiprocessing can be symmetric or asymmetric. | Multithreading is not classified. |
Memory | Multiprocessing allocates separate memory and resources for each process or program. | Multithreading threads belonging to the same process share the same memory and resources as that of the process. |
Pickling objects | Multithreading avoids pickling. | Multiprocessing relies on pickling objects in memory to send to other processes. |
Program | Multiprocessing system allows executing multiple programs and tasks. | Multithreading system executes multiple threads of the same or different processes. |
Time taken | Less time is taken for job processing. | A moderate amount of time is taken for job processing. |
Explain Process Management
Process management involves various tasks like creation, scheduling, termination of processes, and a dead lock. Process is a program that is under execution, which is an important part of modern-day operating systems.
Process Architecture
- Stack: The Stack stores temporary data like function parameters, returns addresses, and local variables.
- Heap: Allocates memory, which may be processed during its run time.
- Data: It contains the variable.
- Text: Text Section includes the current activity, which is represented by the value of the Program Counter.
Process States
A process state is a condition of the process at a specific instant of time. It also defines the current position of the process.
- New: The new process is created when a specific program calls from secondary memory/ hard disk to primary memory/ RAM a
- Ready: In a ready state, the process should be loaded into the primary memory, which is ready for execution.
- Waiting: The process is waiting for the allocation of CPU time and other resources for execution.
- Executing: The process is an execution state.
- Blocked: It is a time interval when a process is waiting for an event like I/O operations to complete.
- Suspended: Suspended state defines the time when a process is ready for execution but has not been placed in the ready queue by OS.
- Terminated: Terminated state specifies the time when a process is terminated
Process Control Blocks
The PCB is a full form of Process Control Block. It is a data structure that is maintained by the Operating System for every process. The PCB should be identified by an integer Process ID (PID). It helps you to store all the information required to keep track of all the running processes.Here, are important components of PCB
- Process state: A process can be new, ready, running, waiting, etc.
- Program counter: The program counter lets you know the address of the next instruction, which should be executed for that process.
- CPU registers: This component includes accumulators, index and general-purpose registers, and information of condition code.
- CPU scheduling information: This component includes a process priority, pointers for scheduling queues, and various other scheduling parameters.
- Accounting and business information: It includes the amount of CPU and time utilities like real time used, job or process numbers, etc.
- Memory-management information: This information includes the value of the base and limit registers, the page, or segment tables. This depends on the memory system, which is used by the operating system.
- I/O status information: This block includes a list of open files, the list of I/O devices that are allocated to the process, etc.
What is Deadlock?
Deadlock is a situation that occurs in OS when any process enters a waiting state because another waiting process is holding the demanded resource. Deadlock is a common problem in multi-processing where several processes share a specific type of mutually exclusive resource known as a soft lock or software.
What is Swapping?
- Swapping is a method in which the process should be swapped temporarily from the main memory to the backing store. It will be later brought back into the memory for continue execution.
- Backing store is a hard disk or some other secondary storage device that should be big enough inorder to accommodate copies of all memory images for all users. It is also capable of offering direct access to these memory images.
Benefits of Swapping
Here, are major benefits/pros of swapping:
- It offers a higher degree of multiprogramming.
- Allows dynamic relocation. For example, if address binding at execution time is being used, then processes can be swap in different locations. Else in case of compile and load time bindings, processes should be moved to the same location.
- It helps to get better utilization of memory.
- Minimum wastage of CPU time on completion so it can easily be applied to a priority-based scheduling method to improve its performance.
What is Paging?
Paging is a storage mechanism that allows OS to retrieve processes from the secondary storage into the main memory in the form of pages. In the Paging method, the main memory is divided into small fixed-size blocks of physical memory, which is called frames. The size of a frame should be kept the same as that of a page to have maximum utilization of the main memory and to avoid external fragmentation. Paging is used for faster access to data, and it is a logical concept.
What is Fragmentation?
- Processes are stored and removed from memory, which creates free memory space, which are too small to use by other processes.
- After sometimes, that processes not able to allocate to memory blocks because its small size and memory blocks always remain unused is called fragmentation. This type of problem happens during a dynamic memory allocation system when free blocks are quite small, so it is not able to fulfill any request.
Two types of Fragmentation methods are:
- External fragmentation
- Internal fragmentation
- External fragmentation can be reduced by rearranging memory contents to place all free memory together in a single block.
- The internal fragmentation can be reduced by assigning the smallest partition, which is still good enough to carry the entire process.
What is Segmentation?
- Segmentation method works almost similarly to paging. The only difference between the two is that segments are of variable-length, whereas, in the paging method, pages are always of fixed size.
- A program segment includes the program's main function, data structures, utility functions, etc. The OS maintains a segment map table for all the processes. It also includes a list of free memory blocks along with its size, segment numbers, and its memory locations in the main memory or virtual memory.
What is Dynamic Loading?
Dynamic loading is a routine of a program which is not loaded until the program calls it. All routines should be contained on disk in a relocatable load format. The main program will be loaded into memory and will be executed. Dynamic loading also provides better memory space utilization.
What is Dynamic Linking?
Linking is a method that helps OS to collect and merge various modules of code and data into a single executable file. The file can be loaded into memory and executed. OS can link system-level libraries into a program that combines the libraries at load time. In Dynamic linking method, libraries are linked at execution time, so program code size can remain small.
What is Inter Process Communication?
- Inter process communication (IPC) is used for exchanging data between multiple threads in one or more processes or programs. The Processes may be running on single or multiple computers connected by a network. The full form of IPC is Inter-process communication.
- It is a set of programming interface which allow a programmer to coordinate activities among various program processes which can run concurrently in an operating system. This allows a specific program to handle many user requests at the same time.
Why IPC?
Here, are the reasons for using the inter process communication protocol for information sharing:
- It helps to speedup modularity
- Computational
- Privilege separation
- Convenience
- Helps operating system to communicate with each other and synchronize their actions.
Different types of IPC:
- Pipes - used for communication between two related processes.
- Message Passing: - mechanism for a process to communicate and synchronize.
- Message Queues - linked list of messages stored within the kernel
- Shared Memory - memory shared between two or more processes that are established using shared memory between all the processes.
- FIFO: Communication between two unrelated processes. It is a full-duplex method, which means that the first process can communicate with the second process, and the opposite can also happen.
What is Virtual Memory?
- Virtual Memory is a storage mechanism which offers user an illusion of having a very big main memory. It is done by treating a part of secondary memory as the main memory. In Virtual memory, the user can store processes with a bigger size than the available main memory.
- Therefore, instead of loading one long process in the main memory, the OS loads the various parts of more than one process in the main memory. Virtual memory is mostly implemented with demand paging and demand segmentation.
What is Demand Paging?
- A demand paging mechanism is very much similar to a paging system with swapping where processes stored in the secondary memory and pages are loaded only on demand, not in advance.
- So, when a context switch occurs, the OS never copy any of the old program's pages from the disk or any of the new program's pages into the main memory. Instead, it will start executing the new program after loading the first page and fetches the program's pages, which are referenced.
- During the program execution, if the program references a page that may not be available in the main memory because it was swapped, then the processor considers it as an invalid memory reference. That's because the page fault and transfers send control back from the program to the OS, which demands to store page back into the memory.
Types of Page Replacement Methods:
1) FIFO - memory selects the page for a replacement that has been in the virtual address of the memory for the longest time.
2) Optimal Algorithm - selects that page for a replacement for which the time to the next reference is the longest.
3) LRU Page Replacement- helps OS to find page usage over a short period of time.
Advantages of Virtual Memory
Here, are pros/benefits of using Virtual Memory:
- Virtual memory helps to gain speed when only a particular segment of the program is required for the execution of the program.
- It is very helpful in implementing a multiprogramming environment.
- It allows you to run more applications at once.
- It helps you to fit many large programs into smaller programs.
- Common data or code may be shared between memory.
- Process may become even larger than all of the physical memory.
- Data / code should be read from disk whenever required.
- The code can be placed anywhere in physical memory without requiring relocation.
- More processes should be maintained in the main memory, which increases the effective use of CPU.
- Each page is stored on a disk until it is required after that, it will be removed.
- It allows more applications to be run at the same time.
- There is no specific limit on the degree of multiprogramming.
- Large programs should be written, as virtual address space available is more compared to physical memory.
Disadvantages of Virtual Memory
Here, are drawbacks/cons of using virtual memory:
- Applications may run slower if the system is using virtual memory.
- Likely takes more time to switch between applications.
- Offers lesser hard drive space for your use.
- It reduces system stability.
- It allows larger applications to run in systems that don't offer enough physical RAM alone to run them.
- It doesn't offer the same performance as RAM.
- It negatively affects the overall performance of a system.
- Occupy the storage space, which may be used otherwise for long term data storage.
Mutex vs Semaphore: What's the Difference?
What is Semaphore?
Semaphore is simply a variable that is non-negative and shared between threads. A semaphore is a signaling mechanism, and a thread that is waiting on a semaphore can be signaled by another thread. It uses two atomic operations, 1)wait, and 2) signal for the process synchronization.A semaphore either allows or disallows access to the resource, which depends on how it is set up.
What is Mutex?
The full form of Mutex is Mutual Exclusion Object. It is a special type of binary semaphore which used for controlling access to the shared resource. It includes a priority inheritance mechanism to avoid extended priority inversion problems. It allows current higher priority tasks to be kept in the blocked state for the shortest time possible. However, priority inheritance does not correct priority- inversion but only minimizes its effect.
The full form of Mutex is Mutual Exclusion Object. It is a special type of binary semaphore which used for controlling access to the shared resource. It includes a priority inheritance mechanism to avoid extended priority inversion problems. It allows current higher priority tasks to be kept in the blocked state for the shortest time possible. However, priority inheritance does not correct priority- inversion but only minimizes its effect.
Parameters | Semaphore | Mutex |
---|---|---|
Mechanism | It is a type of signaling mechanism. | It is a locking mechanism. |
Data Type | Semaphore is an integer variable. | Mutex is just an object. |
Modification | The wait and signal operations can modify a semaphore. | It is modified only by the process that may request or release a resource. |
Resource management | If no resource is free, then the process requires a resource that should execute wait operation. It should wait until the count of the semaphore is greater than 0. | If it is locked, the process has to wait. The process should be kept in a queue. This needs to be accessed only when the mutex is unlocked. |
Thread | You can have multiple program threads. | You can have multiple program threads in mutex but not simultaneously. |
Ownership | Value can be changed by any process releasing or obtaining the resource. | Object lock is released only by the process, which has obtained the lock on it. |
Types | Types of Semaphore are counting semaphore and binary semaphore. | Mutex has no subtypes. |
Operation | Semaphore value is modified using wait () and signal () operation. | Mutex object is locked or unlocked. |
Resources Occupancy | It is occupied if all resources are being used and the process requesting for resource performs wait () operation and blocks itself until semaphore count becomes >1. | In case if the object is already locked, the process requesting resources waits and is queued by the system before lock is released. |
RAM vs ROM: What's the Difference?
Parameters | RAM | ROM |
---|---|---|
Usage | RAM allows the computer to read data quickly to run applications. | ROM stores all the application which is needed to boot the computer initially. It only allows for reading. |
Volatility | RAM is volatile. So, its contents are lost when the device is powered off. | It is non-volatile, i.e., its contents are retained even if the device is powered off |
Accessibility | Information stored in the RAM is easily accessed. | The processor can't directly access the information that is stored in the ROM. In order to access ROM information first, the information is transferred into the RAM, and then it can be executed by the processor. |
Read/Write | Both R (read) and W (write) operations can be performed over the information which is stored in the RAM. | The ROM memory allows the user to read the information. But, the user can't alter the information. |
Storage | RAM is used to store temporary information. | ROM memory is used to store permanent information, which is non-erasable. |
Speed | The access speed of RAM is faster. | Its speed is slower in comparison with RAM. Therefore, ROM can't boost up the processor speed. |
Cost | The price of RAM is quite high. | The price of ROM is comparatively low. |
Chip size | Physical size of RAM chip is bigger than ROM chip. | Physical size of ROM chip is smaller than the RAM chip of same storage capacity. |
Preservation of Data | Electricity is needed in RAM to flow and to preserve information | Electricity is not required to flow and preserving information |
Structure | The RAM chip is in rectangle form and is inserted over the motherboard of the computer. | Read-only memory (ROM) is a type of storage medium that permanently stores data on personal computers (PCs) and other electronic devices. |
How to delete zombie process?
ReplyDelete