martin
martin

Reputation: 96999

How to gently kill Firefox process on Linux/OS X

I'm doing some automation with Firefox and although I can open Firefox window from shell, I'm not able to terminate it properly. If I kill Firefox process with kill -3 or kill -2 command the next time I open a new Firefox window it asks me if I want to run in safe-mode. I understand that calling kill -9 could confuse Firefox so it would try to run in safe-mode but -3 should be fine.

Do you have any idea how to gently tell Firefox to close properly?

Upvotes: 15

Views: 31798

Answers (8)

user16468971
user16468971

Reputation:

You can close the FF by kill and PID

#!/bin/bash

firefox & PID=$! # Start Firefox and get PID for later

Running the FF some time

kill -15 $PID # Soft Kill of FF

Upvotes: 0

Deepak Singh
Deepak Singh

Reputation: 460

First Run xkill command after that click on window which one you want close

    xkill

Upvotes: 0

serv-inc
serv-inc

Reputation: 38307

A bit more gentle

As @skybert indicated in the comment, you can

set browser.sessionstore.resume_from_crash to false.

in about:config, which

will rid you of the "Ups, something went wrong ..." message.

To get rid of the safe-mode message, you can set the config

toolkit.startup.max_resumed_crashes to -1

or (just set) the environment variable MOZ_DISABLE_AUTO_SAFE_MODE.

Less gentle

In lack of a better solution, you can remove sessionstore.js from the profile folder after the killall.

This is no more "gentle" than your solution, but it fixes the "Safe Mode" message:

Source: https://support.mozilla.org/en-US/questions/817752

Upvotes: 3

Ahmed Lotfy
Ahmed Lotfy

Reputation: 3906

For Firefox in OSX:

killall 'firefox'

Upvotes: 2

chepner
chepner

Reputation: 532498

In Mac OS X, you could use AppleScript to close it (adjust the application name as necessary; I don't have FireFox installed to test):

$ osascript -e 'tell application "FireFox"
quit
end tell'

This should trigger the same event that the Quit menu command triggers, so FireFox should shut down cleanly.

Obviously, this won't work in Linux.

Upvotes: 3

Victor
Victor

Reputation: 116

You can first get the Pid of firefox with

pgrep firefox

and after use kill to stop firefox kill [pid]

kill `pgrep firefox`

Upvotes: 2

anishsane
anishsane

Reputation: 20980

How about

wmctrl -c "Mozilla Firefox"

?

Is it what you want?

NOTEs:

  1. This command may need to be fired in same DISPLAY & probably same virtual desktop, on which your firefox is running.
  2. Only first matching window will be closed. You may need to loop this command.

Upvotes: 8

anubhava
anubhava

Reputation: 786319

You can use pkill with the process name:

pkill -f firefox

Upvotes: 17

Related Questions