Tuesday, July 26, 2016

Could not get lock /var/lib/dpkg/lock

Today, I tried to install Git on my Ubuntu machine and during that I received following exception related to locking. In my this post, I have shared all commands and error messages with you.


Command
sudo apt-get install git

Error Message
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?



After searching above message, I found a command

sudo lsof /var/lib/dpkg/lock

after pressing ENTER, it might asked you for password. Type the password and in result you might get following output

lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
unattende        1468 root    5uW  REG    8,1        0 154817 /var/lib/dpkg/lock

Type following command to kill the session with provided PID by your system. In my case PID # was 1468. I use following command to kill this process id.

sudo kill 1468

After execution of above statement, now I was able to download GIT by using following command again which I executed in start.

sudo apt-get install git

In case if this article helps you then please leave a comment to increase its credibility.

Thanks.

Sunday, July 24, 2016

NodeJS Series: Calling Sleep Method.

Dear Friends,

This is my first article about NodeJS, I am currently exploring it and problems which I found during my learning sessions, I will share it to you with my blog posts.

Today while writing some code, I come across the need of sleep functionality between two transactions. While doing google, I found "sleep" library which provide required functionality.

Calling of sleep method is simple e.g.,

sleep.sleep(1) // time will be defined in seconds 

But before that you need sleep library / package. To download it, use following npm command

npm install sleep

After successful installation, write following code to test this functionality.

var sleep = require('sleep');

function callLoops()
{
for(var a=1;a<10;a++)
{
console.log('%d',a);
sleep.sleep(1); //times in seconds.
}
}

callLoops();

and save this code in myExample.js file.

Execute the file with following command

node myExample.js

Congratulations...... You have achieved the goal.

That's all for now folks..... If this post help you then please increase its credibility by posting your comments.

Thanks.

Docker Tutorial

 I have listed all the necessary commands of Docker below. In case if any is missing or if any improvement required, please share in comment...