diff --git a/app/Makefile.am.inc b/app/Makefile.am.inc
index 120b8aed..0a25a6e4 100644
--- a/app/Makefile.am.inc
+++ b/app/Makefile.am.inc
@@ -61,6 +61,7 @@ flatpak_SOURCES = \
app/flatpak-builtins-search.c \
app/flatpak-builtins-repair.c \
app/flatpak-builtins-create-usb.c \
+ app/flatpak-builtins-kill.c \
app/flatpak-table-printer.c \
app/flatpak-table-printer.h \
app/flatpak-complete.c \
diff --git a/app/flatpak-builtins-kill.c b/app/flatpak-builtins-kill.c
new file mode 100644
index 00000000..2684362c
--- /dev/null
+++ b/app/flatpak-builtins-kill.c
@@ -0,0 +1,137 @@
+/*
+ * Copyright © 2018 Red Hat, Inc
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see .
+ *
+ * Authors:
+ * Matthias Clasen
+ */
+
+#include "config.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include "libglnx/libglnx.h"
+
+#include "flatpak-builtins.h"
+#include "flatpak-instance.h"
+
+static GOptionEntry options[] = {
+ { NULL }
+};
+
+static gboolean
+kill_instance (const char *id,
+ GError **error)
+{
+ g_autoptr(GPtrArray) instances = NULL;
+ int j;
+ int killed = 0;
+
+ instances = flatpak_instance_get_all ();
+
+ for (j = 0; j < instances->len; j++)
+ {
+ FlatpakInstance *instance = (FlatpakInstance *)g_ptr_array_index (instances, j);
+ if (strcmp (id, flatpak_instance_get_app (instance)) == 0 ||
+ strcmp (id, flatpak_instance_get_id (instance)) == 0)
+ {
+ pid_t pid = flatpak_instance_get_child_pid (instance);
+ kill (pid, SIGKILL);
+ killed++;
+ }
+ }
+
+ g_debug ("Killed %d instances", killed);
+
+ if (killed == 0)
+ return flatpak_fail (error, _("%s is not running."), id);
+
+ return TRUE;
+}
+
+gboolean
+flatpak_builtin_kill (int argc,
+ char **argv,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GOptionContext) context = NULL;
+ const char *instance;
+
+ context = g_option_context_new (_("INSTANCE - Stop a running application"));
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+
+ if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error))
+ return FALSE;
+
+ if (argc > 2)
+ {
+ usage_error (context, _("Extra arguments given"), error);
+ return FALSE;
+ }
+
+ if (argc < 2)
+ {
+ usage_error (context, _("Must specify the app to kill"), error);
+ return FALSE;
+ }
+
+ instance = argv[1];
+
+ return kill_instance (instance, error);
+}
+
+gboolean
+flatpak_complete_kill (FlatpakCompletion *completion)
+{
+ g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GPtrArray) instances = NULL;
+ int i;
+
+ context = g_option_context_new ("");
+ if (!flatpak_option_context_parse (context, options, &completion->argc, &completion->argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, NULL, NULL))
+ return FALSE;
+
+ switch (completion->argc)
+ {
+ case 0:
+ case 1: /* NAME */
+ flatpak_complete_options (completion, global_entries);
+ flatpak_complete_options (completion, options);
+
+ instances = flatpak_instance_get_all ();
+ for (i = 0; i < instances->len; i++)
+ {
+ FlatpakInstance *instance = (FlatpakInstance *)g_ptr_array_index (instances, i);
+ flatpak_complete_word (completion, "%s ", flatpak_instance_get_app (instance));
+ flatpak_complete_word (completion, "%s ", flatpak_instance_get_id (instance));
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return TRUE;
+}
diff --git a/app/flatpak-builtins.h b/app/flatpak-builtins.h
index 50d8da9d..7c81474f 100644
--- a/app/flatpak-builtins.h
+++ b/app/flatpak-builtins.h
@@ -98,6 +98,7 @@ BUILTINPROTO (config)
BUILTINPROTO (search)
BUILTINPROTO (repair)
BUILTINPROTO (create_usb)
+BUILTINPROTO (kill)
#undef BUILTINPROTO
diff --git a/app/flatpak-main.c b/app/flatpak-main.c
index 5906d113..03c7e801 100644
--- a/app/flatpak-main.c
+++ b/app/flatpak-main.c
@@ -82,6 +82,7 @@ static FlatpakCommand commands[] = {
{ "make-current", N_("Specify default version to run"), flatpak_builtin_make_current_app, flatpak_complete_make_current_app },
{ "enter", N_("Enter the namespace of a running application"), flatpak_builtin_enter, flatpak_complete_enter },
{ "ps", N_("Enumerate running applications"), flatpak_builtin_ps, flatpak_complete_ps },
+ { "kill", N_("Stop a running application"), flatpak_builtin_kill, flatpak_complete_kill },
/* translators: please keep the leading newline and space */
{ N_("\n Manage file access") },
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 9d3b81bf..2326399b 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -57,6 +57,7 @@ man1 = \
flatpak-search.1 \
flatpak-create-usb.1 \
flatpak-repair.1 \
+ flatpak-kill.1 \
$(NULL)
man5 = \
diff --git a/doc/flatpak-docs.xml.in b/doc/flatpak-docs.xml.in
index f1d7bb6e..f87811fc 100644
--- a/doc/flatpak-docs.xml.in
+++ b/doc/flatpak-docs.xml.in
@@ -39,6 +39,7 @@
+
diff --git a/doc/flatpak-kill.xml b/doc/flatpak-kill.xml
new file mode 100644
index 00000000..b44f964c
--- /dev/null
+++ b/doc/flatpak-kill.xml
@@ -0,0 +1,103 @@
+
+
+
+
+
+
+ flatpak kill
+ flatpak
+
+
+
+ Developer
+ Matthias
+ Clasen
+ mclasen@redhat.com
+
+
+
+
+
+ flatpak kill
+ 1
+
+
+
+ flatpak-kill
+ Stop a running application
+
+
+
+
+ flatpak kill
+ INSTANCE
+
+
+
+
+ Description
+
+
+ Kill a running sandbox. INSTANCE can be
+ either the numeric instance ID or the application ID of a running
+ Flatpak.
+
+
+
+
+
+ Options
+
+ The following options are understood:
+
+
+
+
+
+
+
+ Show help options and exit.
+
+
+
+
+
+
+
+
+ Print debug information during command processing.
+
+
+
+
+
+
+
+ Print OSTree debug information during command processing.
+
+
+
+
+
+
+ Examples
+
+
+ $ flatpak kill org.gnome.Todo
+
+
+
+
+
+ See also
+
+
+ flatpak1,
+ flatpak-run1,
+ flatpak-ps1
+
+
+
+
+
diff --git a/doc/flatpak.xml b/doc/flatpak.xml
index 40f318d5..f69f577a 100644
--- a/doc/flatpak.xml
+++ b/doc/flatpak.xml
@@ -237,6 +237,13 @@
Run an application.
+
+ flatpak-kill1
+
+
+ Stop a running application.
+
+
flatpak-override1