Thread Synchronization – Mutex Explained With Simple Example

A Mutex is basically a lock that is locked before accessing any critical section of code to ensure only one thread at a time can access it. Mutex is unlocked when the thread is done processing. Thus, mutex can also be thought as “Mutually exclusive flag” to ensure all other threads are blocked to a certain section of code when one thread is already accessing it.

(more…)
Thread Synchronization – Mutex Explained With Simple Example Read More

Inter Process Communications – Pipes Explained With Simple Example

Pipes are one of the oldest and simplest form of Inter-Process communications. Typically, a pipe is half-duplex way of transmitting data between two processes which means data can be passed in one direction only. It can be used only between processes having common parent.
Normally pipes are used between parent and child processes.

(more…)
Inter Process Communications – Pipes Explained With Simple Example Read More

Program to Find Duplicate Files in a File System

Given in a directory, we have to write a program to find duplicate files in the file system.
For eg:
Let’s assume we have following files and it’s content in the file system.

char files[][80][80] = {{"1.txt", "abcd"},
                        {"2.txt", "efgh"},
                        {"3.txt", "efgh"},
                        {"4.txt", "abcd"},
                        {"5.txt", "efgh"},
                        {"6.txt", "efgh"},
                        {"7.txt", "xyz"}

Based on above input, duplicate files are – “1.txt” and “4.txt”. “2.txt”, “3.txt”, “5.txt” and “6.txt” are also duplicate files.

(more…)
Program to Find Duplicate Files in a File System Read More

Bellman Ford’s Shortest Path Algorithm

Shortest path algorithms are designed to find the minimum cost path between two nodes in a graph. This algorithm can be used to find out the fastest way to reach from one place to another or it can be used to find cheapest way to fly or travel between source and destination.
A weighted graph is a graph in which every edge is not of same weight. In this weighted graph, we have to find the shortest path to all the vertices from a given vertices.
Before going ahead have a look into Graph Basics.

(more…)
Bellman Ford’s Shortest Path Algorithm Read More

Dijsktra Shortest Path Algorithm Explained with Simple Example

Shortest path algorithms are designed to find the minimum cost path between two nodes in a graph. This algorithm can be used to find out the fastest way to reach from one place to another or it can be used to find cheapest way to fly or travel between source and destination.
A weighted graph is a graph in which every edge is not of same weight. In this weighted graph, we have to find the shortest path to all the vertices from a given vertices.
Before going ahead have a look into Graph Basics.

(more…)
Dijsktra Shortest Path Algorithm Explained with Simple Example Read More

Shortest path in unweighted graph explained with simple example

Shortest path algorithms are designed to find the minimum cost path between two nodes in a graph. This algorithm can be used to find out the fastest way to reach from one place to another or it can be used to find cheapest way to fly or travel between source and destination.
An unweighted graph is a graph in which all the edges are of same cost. In this unweighted graph, we have to find the shortest path to all the vertices from a given vertices. This algorithm is very much similar to BFS.
Before going ahead have a look into Graph Basics.

(more…)
Shortest path in unweighted graph explained with simple example Read More

Network Address Translation Explained With Simple Example

Network Address Translation or NAT is a method to map multiple local private IP address to one or more public IP addresses. To achieve this generally a network device for eg: Router which is sitting in the private network, changes the source IP and port field of the IP header in a packet.

Since IP Addresses are limited (IPv4) and as internet devices are too large in number. Hence, NAT is used to apply one or more public IP addresses to a pool of devices present in a private network to save IP addresses.
Theoretically using NAT one public IP Address is sufficient for an ISP hosting a large number of subscribers.

(more…)
Network Address Translation Explained With Simple Example Read More

Difference Between Process and Threads

A program in execution is called a process. There can be multiple instances of a program running in the system which are identified by a unique id called process id. Operating System ensures that each process has a unique id which is always a non-negative integer number.

A thread is a lightweight process which can only be used inside a process. Like process, thread also has a unique identifier to identify threads which are called thread ids. Unlike process ids, thread ids are only unique to a process and one process threads are unknown to other process.

(more…)
Difference Between Process and Threads Read More