POSIX deadlock detection: A walk through linux kernel source

A note to readers: The following content is completely oriented for developers, especially in C. In case you find it difficult to understand certain terms, please help yourselves to google around and understand the concepts. I have tried including links wherever necessary in order to effectively interpret the article(see provided links towards the end). Last but not least, as per POSIX documentation[1], deadlock detection is guaranteed for locks between different processes and not between different threads inside a process or between threads belonging to different processes.

As you can see from the heading of this article, I am aiming at explaining the source code for detecting POSIX deadlocks. Before that let me quickly brief the concept of deadlock in operating systems. A deadlock is a situation where two processes sharing the same resource are preventing each other from accessing the resource which will result in an undefined wait for those resources. Following are the four necessary conditions(Coffman conditions)[2] which leads to a deadlock scenario:

* Mutual exclusion
* Hold and Wait
* No pre-emption
* Circular wait

Read More »

[Bash Script-2] Download files from multiple urls with wget in a background script

Image

For linux guys, wget is always a good old friend. Citing from the man page, it is a non-interactive network downloader. In situations where we need to download from multiple urls, wget can take input from files which contain those urls. ‘ -i ‘ option can be used along with wget to specify the input file. Apart from that you can even write a small script and run it in background as is explained below.

Suppose I need to download certain files from the following urls (Note:- Urls provided here are provided as a matter of example. They may or Read More »

[Bash Script -1] For rotating two-dimensional matrix

Image

#!/bin/bash

#Here we use the row major representation of a two-dimensional matrix.
#Array ‘x’ is the original matrix and  ‘r’ is the matrix after rotation.
#Matrix rotations in multiples of 90 degrees can be done by calling the rotate function repeatedly.

#perform clockwise-rotation by 90 degrees
rotate () {
t=(“$@”)
let i=0
while [ $i -lt $n ]
do
let j=0
while [ $j -lt $n ]
do
Read More »