1

I'm pretty sure this is a duplicate somewhere. I apologize for the repeat. I'm running Xubuntu 14.04. For some odd reason my pc is running slow today, so I thought it might have something to do with the software, so I did an update, and sudo apt-get update returns an error:

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?

I tried the answer given in apt-get install is not working because of dpkg, how to solve and this is the following result:

$ sudo lsof /var/lib/dpkg/lock
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
aptitude 2166 root    3uW  REG  252,0        0 49021509 /var/lib/dpkg/lock

$ sudo lsof /var/lib/apt/lists/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.

$ sudo lsof /var/cache/apt/archives/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.

$ sudo dpkg --configure -a
dpkg: error: dpkg status database is locked by another process
  1. How do I fix this?
  2. Could someone walk me thru the steps?
  3. Why would I need a "lock" on an open directory?
  4. How do I find what process is using it?
  5. How do I check my hardware if that's the culprit??

I will try a reboot, and see if that fixes anything. Be right back.


OK, NOW after rebooting I get the following results:|

$ sudo lsof /var/lib/dpkg/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.

$ sudo lsof /var/lib/apt/lists/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.

$ sudo lsof /var/cache/apt/archives/lock
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
lsof: status error on /var/cache/apt/archives/lock: No such file or directory
lsof 4.86
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.

I also tried

sudo dpkg --configure -a

which may have worked cause when I did

sudo apt-get update

I got NO ERRORS.

0

3 Answers 3

2

I'm gonna answer your questions a bit out of order, because I can.

How do I check my hardware if that's the culprit??

Is your computer working? If so, your hardware isn't causing the problem.

Why would I need a "lock" on an open directory?

DPKG/Apt locks /var/lib/dpkg to ensure that it can install software in peace, without causing any conflicts to the database of installed packages (present at /var/lib/dpkg/status). It's a safety mechanism to keep APT from blowing itself up by accident.

How do I find what process is using it?

You already have! Look at the output of: sudo lsof /var/lib/dpkg/lock:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
aptitude 2166 root    3uW  REG  252,0        0 49021509 /var/lib/dpkg/lock

The program aptitude (a pretty package manager) is active, and is the current owner of the lock.

How do I fix this? Could someone walk me thru the steps?

There are a few things you can do.

First off, you can just break the lock by running sudo rm /var/lib/dpkg/lock. However, it's a good idea not to break this lock to force other apt processes to run, as you may be interrupting something important, which may leave your system in an unusable state. Only do this if you're 100% sure that apt or dpkg isn't running. You can check this by running ps -aux | grep dpkg or ps -aux | grep apt. If either of these return anything other than a line with grep in it, it's unsafe to break the lock.

Secondly, you can go around to all of your terminals to see where aptitude is being run, and to check up on it. If you cannot find the terminal that it's on, the w command will help you a lot.

Third, you can just kill the process by force, although this may still need you to break the lock. Do this by running sudo kill <PID>, where <PID> is the number in the lsof entry, in your case, 2166. Do not run kill -9 for apt, as it will forcefully kill it, while regular kill will give apt a chance to clean everything up before it dies. You can also kill the process by rebooting, logging off, or exiting the terminal it's running in.

If you do forcefully kill apt and break the lock, it's a very good idea to run dpkg --configure -a to let DPKG fix what was potentially broken.

4
  • so - 'sudo kill 2166' - will stop the process by force? Bad news (maybe), I already used - sudo rm /var/lib/dpkg/lock - am I screwed or is there hope?
    – hienz1
    Sep 16, 2016 at 4:50
  • @hienz1 If you rebooted your computer and have already done dpkg --configure -a, your system will be fine. To answer your second question, the kill command will (by default) send something called Signal 15, which asks a process nicely to gracefully exit, which is usually safe. By adding -9, the kill command will forcefully close the command, which can be unsafe. See man kill for more details.
    – Kaz Wolfe
    Sep 16, 2016 at 4:52
  • THANK YOU so much, Kaz Wolfe, that's a great weight off my shoulders. :-)
    – hienz1
    Sep 16, 2016 at 4:55
  • @hienz1 No worries! It's what AskUbuntu is here for!
    – Kaz Wolfe
    Sep 16, 2016 at 4:56
0
  1. How do I find what process is using it?
ps -fea | grep apt

Then, once you have identified the process, you may need to kill it.

kill -9 nnnn

Where nnnn is the process number.

[Restarting the computer will also kill it but often just logging out and back in works, depending who owns the process causing the issue.]

2
  • The results of ................... '$ ps -fea | grep apt ........................ hienz1 , 4126 , 2855 , 0 00:31 , pts/0 , 00:00:00 , grep --color=auto apt'
    – hienz1
    Sep 16, 2016 at 4:38
  • which is the process number?
    – hienz1
    Sep 16, 2016 at 4:43
0
  1. Restart your system to ensure apt is not running
  2. Delete the lock file (sudo rm /var/lib/dpkg/lock)

The lock file prevents multiple instances of apt to run at once

5
  • Thanks for the reply. Which file should I delete, what's it called? And is the terminal command to do that "sudo apt-get del"?
    – hienz1
    Sep 16, 2016 at 4:20
  • The command is rm and the file is /var/lib/dpkg/lock Sep 16, 2016 at 4:23
  • results: $ rm /var/lib/dpkg/lock rm: remove write-protected regular empty file ‘/var/lib/dpkg/lock’? y rm: cannot remove ‘/var/lib/dpkg/lock’: Permission denied
    – hienz1
    Sep 16, 2016 at 4:26
  • You need to use sudo Sep 16, 2016 at 4:27
  • sudo rm /var/lib/dpkg/lock - returned no activity, so I'm assuming it worked
    – hienz1
    Sep 16, 2016 at 4:28

Not the answer you're looking for? Browse other questions tagged .