[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH] Shell: Neuer Befehl kill



+ shell: kill-Befehl (sendet SIGTERM)
---
 src/modules/c/shell/cmds/kill.c |   78 +++++++++++++++++++++++++++++++++++++++
 src/modules/c/shell/commmands.c |    1 +
 src/modules/c/shell/shell.c     |    1 +
 src/modules/c/shell/shell.h     |    1 +
 4 files changed, 81 insertions(+), 0 deletions(-)
 create mode 100644 src/modules/c/shell/cmds/kill.c

diff --git a/src/modules/c/shell/cmds/kill.c b/src/modules/c/shell/cmds/kill.c
new file mode 100644
index 0000000..97e5258
--- /dev/null
+++ b/src/modules/c/shell/cmds/kill.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2009 The tyndur Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the tyndur Project
+ * by Kevin Wolf
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the tyndur Project
+ *     and its contributors.
+ * 4. Neither the name of the tyndur Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <lost/config.h>
+
+#include <errno.h>
+#include <signal.h>
+
+static void kill_display_usage(void);
+
+#ifdef CONFIG_SHELL_BUILTIN_ONLY
+    int shell_command_kill(int argc, char* argv[], const char* args)
+#else
+    int main(int argc, char* argv[])
+#endif
+{
+    int ret;
+
+    if (argc != 2) {
+        kill_display_usage();
+        return -1;
+    }
+
+    pid_t pid = atoi(argv[1]);
+    if (!pid) {
+        printf("Prozess %d nicht gefunden\n", pid);
+        return EXIT_FAILURE;
+    }
+
+    ret = kill(pid, SIGTERM);
+    if (ret < 0) {
+        printf("Konnte Prozess %d nicht beenden: %d (%s)\n", pid, errno,
+            strerror(errno));
+        return EXIT_FAILURE;
+    }
+
+    return EXIT_SUCCESS;
+}
+
+static void kill_display_usage()
+{
+    puts("\nAufruf: kill <Prozessnummer>");
+}
+
diff --git a/src/modules/c/shell/commmands.c b/src/modules/c/shell/commmands.c
index bc41bba..25d0cb7 100644
--- a/src/modules/c/shell/commmands.c
+++ b/src/modules/c/shell/commmands.c
@@ -163,6 +163,7 @@ int shell_command_help(int argc, char* argv[], const char* args)
     puts("  free           Zeigt den Speicherverbrauch des Systems an");
     puts("  ps             Zeigt eine Liste mit allen Prozessen an");
     puts("  pstree         Zeigt die Prozesshierarchie als Baum an");
+    puts("  kill <PID>     Beendet den Prozess <PID>");
     puts("  dbg_st <PID>   Zeigt einen Stack Backtrace des Prozesses <PID>"
         " an");
     
diff --git a/src/modules/c/shell/shell.c b/src/modules/c/shell/shell.c
index 9470fe5..3f1acf5 100644
--- a/src/modules/c/shell/shell.c
+++ b/src/modules/c/shell/shell.c
@@ -83,6 +83,7 @@ shell_command_t shell_commands[] = {
     {"date",        &shell_command_date},
     {"echo",        &shell_command_echo},
     {"free",        &shell_command_free},
+    {"kill",        &shell_command_kill},
     {"ls",          &shell_command_ls},
     {"irc",         &shell_command_irc},
     {"mkdir",       &shell_command_mkdir},
diff --git a/src/modules/c/shell/shell.h b/src/modules/c/shell/shell.h
index 53a757d..b715ed3 100644
--- a/src/modules/c/shell/shell.h
+++ b/src/modules/c/shell/shell.h
@@ -68,6 +68,7 @@ int shell_command_clear(int argc, char* argv[], const char* args);
     int shell_command_echo(int argc, char* argv[], const char* args);
     int shell_command_irc(int argc, char* argv[], const char* args);
     int shell_command_free(int argc, char* argv[], const char* args);
+    int shell_command_kill(int argc, char* argv[], const char* args);
     int shell_command_ls(int argc, char* argv[], const char* args);
     int shell_command_mkdir(int argc, char* argv[], const char* args);
     int shell_command_pipe(int argc, char* argv[], const char* args);
-- 
1.6.0.2