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?– ZoredacheMar 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'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
SIGTERM
is the same as signal15
, hence--signal TERM
, or just leave it out sinceSIGTERM
is the default signalwmctrl
works with Unity and some others but it does not work with all window managerswmctrl -c
closes 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
--oldest
is not an option: using-o
works. Feb 10, 2015 at 16:01 -
the
-f
argument 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. Mar 4, 2015 at 17:13 -
-
In Ubuntu 18.04, how could I make this to be executed immediately after triggering a restart or a shutdown?. 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
.– slyblotyMar 14, 2012 at 0:06 -
wmctrl cannot close system tray "Chrome Apps".
pkill -o chrome
does though. Feb 10, 2015 at 16:00 -
1
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
kill
orkillall
where Chrome sees it as a crash, and asking to restore.– slyblotyMar 13, 2012 at 18:54 -
1
-
6Actually,
SIGQUIT
is not usually sent to applications when asked to close (I don't know any WMs that do this).WM_DELETE_WINDOW
is the standard. Mar 13, 2012 at 20:29 -
2@blacklemon67
kill -15 <pid_of_chrome>
did what I was looking for. But,google-chrome
has multiple pids and it took a few tried to actually get the right one.– slyblotyMar 14, 2012 at 0:26
For Ubuntu just simply enter:
exit google-chrome