Why does Firefox refuse to die despite killing it with pkill -9?

7,428

Solution 1

Do not use kill -9 if not absolutely necessary. Always try kill (without -9) first.

Your trouble "killing" firefox is likely be a result of a previous kill -9 (or pkill -9).

I think this is what happened in your case:

  1. Firefox is running. Lockfiles in your profile dir.
  2. You did pkill -9 -f firefox. Firefox is killed instanly. Lockfiles still in your profile dir.
  3. You start a new firefox process.
  4. The new firefox process sees the lockfiles in the profile directory and thinks that another firefox process is still running and refuses to start with a misleading error message.
  5. You are confused by the error message and think that firefox was not killed previously.
  6. You try to keep killing firefox which has no effect because there is no firefox process running.

If you are sure that firefox is killed (check with pgrep -fl firefox) you can manually remove the lockfiles from your profile. For more information see this mozillazine article: http://kb.mozillazine.org/Profile_in_use.

For more explanation about why not kill -9 see this question and answer: When should I not kill -9 a process?.


Background info:

Firefox maintains lockfiles in the profile directory. The lockfiles are there to prevent two instances of firefox accessing the same profile at the same time.

If you start firefox it will check for the lockfiles first. If there are no lockfiles then firefox will place lockfiles and start normally. If there already are lockfiles then firefox will assume that this profile is used by another instance of firefox and show the (potentially misleading) error message that there already is an instance running.

The error message can be misleading because firefox only checks for the lockfiles. It does not check whether there actually are firefox processes running. Sometimes there really are no other firefox instances running. it is just the lockfiles that are left over from a previous instance that for whatever reason were not deleted correctly.

If you close firefox normally it will do some maintenance work before actually shutting down. If you observe the processes (for example using top) you will notice firefox not disappearing immediately from the process list. also that firefox is using a lot of processor at this time. Among other work that firefox is doing at this time is to remove the lockfiles so that the profile will be free to use for the next invocation of firefox.

If you kill firefox (without -9) then firefox will try to shutdown quickly but it will still do some maintenance work like deleting the lockfiles. that also means that firefox will not disappear instantly from the list of processes.

This is actually normal and expected behavious of software. Many software have some state in working memory that is prudent to save to disk upon termination. If termination is requested (by the user clicking the close button, by a kill without -9, or by ctrl+c in the terminal) the software gets notified of this and will start to do the maintenance work and then terminate.

If you kill -9 a process then that process will not get notified of the termination request instead it is killed instantly. if you kill -9 firefox then firefox is killed instantly and cannot remove the lockfiles. and the next time you start firefox you will get the misleading error message.

That is why you should not use kill -9 if not absolutely necessary, and most of the time it is not absolutely necessary.

Solution 2

As far as I know, firefox creates a file called lockor something like that in ~/.mozilla/firefox/<your_profile>/ when it is executed. I don't know the exact behaviour, but sometimes it hinders you to run a second instance of firefox, or, if it is not deleted after closing firefox, to run a single instance at all. Try deleting this file, it should help.

Share:
7,428
jshthornton
Author by

jshthornton

Updated on September 18, 2022

Comments

  • jshthornton
    jshthornton over 1 year

    I am issuing the following command to kill Firefox on my Red Hat Linux box:

    [subhrcho@slc04lyo ~]$ pkill -9 -f firefox
    [subhrcho@slc04lyo ~]$ 
    

    However, when I try to invoke Firefox through Applications -> Internet -> Firefox, it says:

    Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

    • ott--
      ott-- about 11 years
      -9 isn't appropriate for most programs, use it for a shell only. With -9 a program can't do any cleanup. Try -15 instead.
    • manatwork
      manatwork about 11 years
      “Firefox is already running, but is not responding.” sounds like a good reason for involving SIGKILL.
    • vonbrand
      vonbrand about 11 years
      In my experience, firefox takes some time before the "already running, not responding" gets cleared up.
    • kmacdonald
      kmacdonald about 11 years
      SIGKILL can't be handled by programs, so they can't perform any cleanup. In the case of Firefox this probably prevents it from getting rid of the profile lock. If you are just trying to terminate firefox normally, use SIGTERM.
    • kmacdonald
      kmacdonald about 11 years
      (Also, if you're not aware, signal 9 (-9) is SIGKILL, see man 7 signal.)
  • schaiba
    schaiba about 11 years
    pidof firefox must be between backticks, they don't seem to appear for whatever reason.
  • manatwork
    manatwork about 11 years
    Better use $() instead of backticks. (GreyCat's Why is $(...) preferred over ... (backticks)? article enumerates additional reasons.)
  • jshthornton
    jshthornton about 11 years
    @schaiba I am seeing a "pidof: Command not found."
  • schaiba
    schaiba about 11 years
    Try @manatwork's solution, then.
  • manatwork
    manatwork about 11 years
    @schaiba, if says “Command not found”, that sounds like the sysvinit-tools package (the one containing pidof on my system) is not installed there.
  • schaiba
    schaiba about 11 years
    @manatwork : I never encountered a modern Linux system, however minimalist it would be, without pidof. What RH version are you on, Geek?
  • vonbrand
    vonbrand about 11 years
    @manatwork, perhaps it just isn't in your PATH, or you have an alias to the wrong command?
  • Sleeping_Giant
    Sleeping_Giant about 11 years
    You didn't mention which version of Firefox (or RH) you're running, but on older versions of Firefox there was also a "firefox-bin" process that would have to be killed as well. On newer versions, if Firefox has hung, there may be a "plugin-container" process hung as well. Firefox may not start with the same error message if the plugin-container is still running (that happens on my system occasionally: Fedora 17, firefox nightly)
  • kmacdonald
    kmacdonald about 11 years
    If there is no firefox process running (which is likely the case, after all processes can't ignore SIGKILL), this is likely to be the cause of the error message.
  • user66001
    user66001 almost 11 years
    Not good idea, for reasons lesmana already mentioned
  • Obiwan Kenoobi
    Obiwan Kenoobi over 6 years
    I do realize the OP was not specifically asking for the information I provided in my answer but I was trying to help by emphasizing this fact about Firefox. I don't think it was really necessary to downvote my answer twice.
  • hackerb9
    hackerb9 over 2 years
    "You think firefox was not killed and you are confused". Okay, 99% likelihood you are right. In my decades of Unix experience I had never seen a process survive kill -9. Until today. Firefox is using up 100% of the CPU and kill -9 is not stopping it. I cannot attach to a debugger as that requires a signal as well, but I'm pretty sure it's a problem in the kernel (Linux 4.9.0). dmesg shows some "hung_task" messages about the zombie children (which did die), but nothing about the parent process. I'm flabbergasted.