From 3a29d4961d525a6048f10844c56db228cf711957 Mon Sep 17 00:00:00 2001
From: Mcdull <30206217+McDull-GitHub@users.noreply.github.com>
Date: Tue, 6 Apr 2021 20:32:14 +0800
Subject: [PATCH] joker stop

---
 main.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- a/main.c
+++ b/main.c
@@ -158,6 +158,26 @@ int main(int argc, char **argv)
         free(s);
         return 0;
     }
+    if(argc == 2 && strcmp(argv[1], "stop") == 0){
+        int i;
+        int pid = 0;
+        i = system("s=`ps -e -o command | grep joker | grep -v grep | grep -v \"joker list\"`; if [ -n \"$s\" ]; then ps -x | grep -F \"`echo \"$s\" | cut -d' ' -f2-`\" | grep -v joker | grep -v grep; fi;");
+        if (i != 0){
+            printf("error: joker is not running!\n");
+            return i;
+        }
+        printf("\nPid of the process you want to terminate -> ");
+        scanf("%d", &pid);
+        if(pid == 0){
+            return 0;
+        }
+        i = kill(pid, SIGTERM);
+        if(i != 0){
+            printf("stop failed\n");
+            return i;
+        }
+        return 0;
+    }
     if(argc == 3 && strcmp(argv[1], "stop") == 0){
         int pid = atoi(argv[2]);
         if(pid == 0){
