0

I get the following 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?

every time I try to install new software and then I tried to kill the process. So I typed in the command 'ps -A | grep apt-get' and get no response from it.

How do I get rid of this lock?

Fabby
  • 34,259

2 Answers2

2

apt-get isn't the only front-end application thing that uses /var/lib/dpkg/lock.

Things like Update Manager and the Software Centre, Synaptic and aptitude all have their own ways of interfacing with the Apt and dpkg databases.

To find out what has it open, you can use fuser:

sudo fuser -u /var/lib/dpkg/lock

Then, if that's safe to kill (I'd advise people always check before using the -k flag), you can kill it and delete the lockfile.

Oli
  • 293,335
  • I get 30+ results when running sudo fuser -cu /var/lib/dpkg/lock, and it's not even locked / in use now. And the -cuk flags immediately kill my login session & all programs – Xen2050 Jan 21 '15 at 12:40
  • @Xen2050 Yeah I copied over the example from the linked thread. I don't really understand the logic in the -c argument because it really breaks it. I've removed it. – Oli Jan 21 '15 at 12:43
  • That works well with just the -c flag, maybe something's changed since 2010 when that answer was written, I almost got the same kill problems as the other comments there (knowing what's "safe to kill" from just the fuser output isn't obvious ;-) And I'm wondering if there's something wrong with lsof, I'll post it as an alternative answer – Xen2050 Jan 21 '15 at 12:54
0

Using lsof <file> seems to work too.

For example, if I have synaptic running (live):

$ sudo lsof /var/lib/dpkg/lock

lsof: WARNING: can't stat() tmpfs file system /cow
      Output information may be incomplete.
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/999/gvfs
      Output information may be incomplete.
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF  NODE NAME
synaptic 20942 root   10uW  REG   0,18        0 39610 /var/lib/dpkg/lock

Then I know that synaptic with PID 20942 is what's opened the lock file, blocking other package management programs.

Xen2050
  • 8,705