Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

After several tries on installing radiotray on Ubuntu Oneiric version, another user came up with the trouble being it the software sources settings. Now that i want to perform the installation of radio tray again apt-get is hanged waiting for the suitable packages for radiotray. Can't even end the process in System Monitor.

I've already performed a logout and didn't kill it, probably a restart will do it. Is there any other way to stop apt-get from running when it's waiting for packages to download?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

First, get the process id (pid) of the apt-get that is running:

ps ax | grep apt-get

Then kill the process by its pid:

sudo kill -9 [pid]

Or use htop, it lists your processes and enables you to send a variety of signals.

share|improve this answer
    
I had to reboot to kill apt-get. Installed htop for possible issues with hanged apps. thanks a lot –  Stbn Jan 14 '12 at 12:26
add comment

Kill precisely

Find the process id via System Monitor, htop, grepping through ps, whatever (I prefer pgrep -l, see below). Let's say it is 4536 this time. Then kill it dead:

kill -9 4536

The shotgun approach

pkill -9 apt-get

That will kill dead any processes that somehow match the pattern "apt-get". You don't have to look up a process number. This corresponds to these processes:

pgrep -l apt-get

The -l option changes the output from only process numbers to numbers + name. This is good because you can check yourself before blasting away. Maybe when you run pkill -9 nuke you accidentally kill the process the-only-thing-preventing-nukelear-world-war.

Wtf is -9?

Normally kill programs like kill and pkill put you in the position of Darth Vader fighting Obi Wan. Vader wants to kill Ben, Ben acknowledges Vader's desire, Ben gracefully accepts death now that his task is done. This is the same as using the -15 option.

But sometimes processes don't want to die. Or they'll gladly die, just as soon as they've finished doing this one little thing. But you need them to die now, not when it's convenient for them. So you use the -9 option.

Why does it keep hanging?

  • Maybe some other process is interfering. It would probably be something called update, or synaptic, or apt, or anything else along these lines. Kill all of these, one by one, retrying your apt-get command after each kill. Worst case scenario, you kill an important process and have to reboot. Not so bad if you're sitting on the couch with your Ubuntu laptop, sucks if you're remoting to a server across the country.

  • Maybe you changed your update sources and apt-get didn't get the memo yet. Run sudo apt-get update. But first make sure there aren't any interfering processes.

I don't have permission to kill anything :|

Tough beans if you don't own the system. But if you do, use sudo in front of each command, like so: sudo pkill -9 process-i-hate. I intentionally didn't include the sudos for you because you oughtn't kill without thought for your binary victims.

Sources

man kill
man grep
man pkill
man pgrep
man ps
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.