Do not use
kill -9 if not absolutely necessary. Always try
Your trouble "killing" firefox is likely be a result of a previous
kill -9 (or
I think this is what happened in your case:
- Firefox is running. Lockfiles in your profile dir.
- You did
pkill -9 -f firefox. Firefox is killed instanly. Lockfiles still in your profile dir.
- You start a new firefox process.
- 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.
- You are confused by the error message and think that firefox was not killed previously.
- 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?.
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.
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
-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.
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.