Exit Google Chrome from terminal

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 signal 15, hence --signal TERM, or just leave it out since SIGTERM is the default signal
  • wmctrl works with Unity and some others but it does not work with all window managers
  • wmctrl -c closes one window at a time so to close all chrome windows you would need something like while wmctrl -c 'Google Chrome'; do sleep 0.2; done

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).