Is there a way to cause google-chrome to quit, from the terminal, besides using killall google-chrome?
I would like to be able to close it from a script without killing it.
- 2What is wrong with kill?Zoredache– Zoredache2012-03-13 19:26:50 +00:00Commented Mar 13, 2012 at 19:26
- 1@Zoredache That it results in different behavior from exiting, and that Chrome uses multiple processes, one of which (the sandbox) is setuid root.Gilles 'SO- stop being evil'– Gilles 'SO- stop being evil'2012-03-13 21:50:57 +00:00Commented Mar 13, 2012 at 21:50
6 Answers
This command exits the chrome process tree gracefully, in all window managers:
pkill --oldest chrome or if you prefer:
/usr/bin/pkill --oldest --signal TERM -f chrome Details:
- gracefully means: avoid seeing “Google Chrome didn't shut down correctly. To repoen ...” next time chrome starts
- chrome browser (e.g. version 39.0.2171.95) traps and gracefully handles
SIGTERM - signal a single process, the root of chrome’s process tree, hence
--oldest SIGTERMis the same as signal15, hence--signal TERM, or just leave it out sinceSIGTERMis the default signalwmctrlworks with Unity and some others but it does not work with all window managerswmctrl -ccloses one window at a time so to close all chrome windows you would need something likewhile wmctrl -c 'Google Chrome'; do sleep 0.2; done
- 2I assume I am using an old version of pkill as
--oldestis not an option: using-oworks.Ken Sharp– Ken Sharp2015-02-10 16:01:04 +00:00Commented Feb 10, 2015 at 16:01 - the
-fargument to pkill is not working for me. I have some other processes running as root that happen to have the word chrome in their command lines, so I just get permission denied. Without the-f, it works perfectly though.Brian Minton– Brian Minton2015-03-04 17:13:07 +00:00Commented Mar 4, 2015 at 17:13 - This still makes me see 'didn't shut down corrently'xtrinch– xtrinch2017-05-12 09:06:05 +00:00Commented May 12, 2017 at 9:06
- In Ubuntu 18.04, how could I make this to be executed immediately after triggering a restart or a shutdown?.Jaime Hablutzel– Jaime Hablutzel2019-05-25 19:12:55 +00:00Commented May 25, 2019 at 19:12
Perhaps wmctrl could be of some assistance. You could use the -c option that closes a window gracefully:
wmctrl -c chrome The string chrome is matched against the window titles. Note that the window might not close if some message pops-up (e.g. when you have multiple tabs open).
- 1This option works flawless, but it required the installation of
wmctrl.slybloty– slybloty2012-03-14 00:06:31 +00:00Commented Mar 14, 2012 at 0:06 - wmctrl cannot close system tray "Chrome Apps".
pkill -o chromedoes though.Ken Sharp– Ken Sharp2015-02-10 16:00:01 +00:00Commented Feb 10, 2015 at 16:00 - 1Only works on X Window Manager. Not a future proof solutionBrnVrn– BrnVrn2022-09-06 06:32:02 +00:00Commented Sep 6, 2022 at 6:32
This works for me:
killall --quiet --signal 15 -- chrome Note that I'm using a rather verbose command to keep it readable in the code, of course you could also issue:
killall -q -15 chrome On Mac OS X, use this instead
pkill -a -i "Google Chrome" What it does is to look for a Google Chrome process, and kill all of its parent processes as well.
From the pkill manual
-a Include process ancestors in the match list. By default, the current pgrep or pkill process and all of its ancestors are excluded (unless -v is used). -i Ignore case distinctions in both the process table and the supplied pattern. As per @keith-cascio ' s answer, you can try to kill the oldest process instead. Note that this did not work for me.
pkill -o -i "Google Chrome" try:
kill -3 <pid_of_chrome> This will send a "QUIT" signal to chrome, which, depending on your window manager, will be what it is usually sent when asked to close.
- 2This acts just like
killorkillallwhere Chrome sees it as a crash, and asking to restore.slybloty– slybloty2012-03-13 18:54:20 +00:00Commented Mar 13, 2012 at 18:54 - 1try 15 instead of 3, thenBlackle Mori– Blackle Mori2012-03-13 19:40:52 +00:00Commented Mar 13, 2012 at 19:40
- 6Actually,
SIGQUITis not usually sent to applications when asked to close (I don't know any WMs that do this).WM_DELETE_WINDOWis the standard.Chris Down– Chris Down2012-03-13 20:29:11 +00:00Commented Mar 13, 2012 at 20:29 - 2@blacklemon67
kill -15 <pid_of_chrome>did what I was looking for. But,google-chromehas multiple pids and it took a few tried to actually get the right one.slybloty– slybloty2012-03-14 00:26:15 +00:00Commented Mar 14, 2012 at 0:26
For Ubuntu just simply enter:
exit google-chrome
- 1The
exitverb takes an optional status value, not a commandChris Davies– Chris Davies2020-10-08 08:26:05 +00:00Commented Oct 8, 2020 at 8:26