From e54c8af7816170e3e13ef70d60e8fa2bf394263a Mon Sep 17 00:00:00 2001 From: turbocat Date: Thu, 1 Apr 2021 22:06:12 +0000 Subject: [PATCH] SHELL: - Added pkill command git-svn-id: svn://kolibrios.org@8662 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/system/shell/all.h | 1 + programs/system/shell/cmd/cmd_pkill.c | 50 ++++++++++++++++++++++ programs/system/shell/globals.h | 1 + programs/system/shell/locale/eng/globals.h | 1 + programs/system/shell/locale/rus/globals.h | 1 + 5 files changed, 54 insertions(+) create mode 100644 programs/system/shell/cmd/cmd_pkill.c diff --git a/programs/system/shell/all.h b/programs/system/shell/all.h index d630ab843c..a6df4420d0 100644 --- a/programs/system/shell/all.h +++ b/programs/system/shell/all.h @@ -27,6 +27,7 @@ void get_file_dir_loc(char *filepath, char *dir_path); #include "cmd/cmd_ls.c" #include "cmd/cmd_ps.c" #include "cmd/cmd_kill.c" +#include "cmd/cmd_pkill.c" #include "cmd/cmd_echo.c" #include "cmd/cmd_date.c" #include "cmd/cmd_exit.c" diff --git a/programs/system/shell/cmd/cmd_pkill.c b/programs/system/shell/cmd/cmd_pkill.c new file mode 100644 index 0000000000..98160c2cc5 --- /dev/null +++ b/programs/system/shell/cmd/cmd_pkill.c @@ -0,0 +1,50 @@ +int cmd_pkill(char param[]) +{ + int i=1, n=0; int process_count=0; + char *buf1k=NULL; + unsigned PID=0; + + #ifdef LANG_RUS + #define PKILL_HELP " pkill <имя_процесса>\n\r" + #define PKILL_KILL " PID: %u - убит\n" + #define PKILL_NOT_KILL " PID: %u - не убит\n" + #define PKILL_NOT_FOUND " Процессов с таким именем не найдено!\n" + #else + #define PKILL_HELP " pkill \n\r" + #define PKILL_KILL " PID: %u - killed\n" + #define PKILL_NOT_KILL " PID: %u - not killed\n" + #define PKILL_NOT_FOUND " No processes with this name were found!\n" + #endif + + + if(!strlen(param)){ + printf(PKILL_HELP); + return TRUE; + } + + buf1k = malloc(1024); + if(buf1k==NULL){ + return FALSE; + } + + while(i!=n){ + n = kol_process_info(i, buf1k); + if(!strnicmp(buf1k+10, param, 10)){ + memcpy(&PID, buf1k+30 ,sizeof(unsigned)); + if(kol_process_kill_pid(PID)){ + printf(PKILL_NOT_KILL, PID); + }else{ + printf(PKILL_KILL, PID); + } + process_count++; + } + i++; + } + + if(!process_count){ + printf(PKILL_NOT_FOUND); + } + + free(buf1k); + return TRUE; +} \ No newline at end of file diff --git a/programs/system/shell/globals.h b/programs/system/shell/globals.h index dd19b85cb6..5363a28a10 100644 --- a/programs/system/shell/globals.h +++ b/programs/system/shell/globals.h @@ -51,6 +51,7 @@ int cmd_exit(char arg[]); int cmd_memory(char arg[]); int cmd_help(char cmd[]); int cmd_kill(char process[]); +int cmd_pkill(char process_name[]); int cmd_ls(char dir[]); int cmd_mkdir(char dir[]); int cmd_more(char file[]); diff --git a/programs/system/shell/locale/eng/globals.h b/programs/system/shell/locale/eng/globals.h index 1e08ab364b..7cfdf2262b 100644 --- a/programs/system/shell/locale/eng/globals.h +++ b/programs/system/shell/locale/eng/globals.h @@ -15,6 +15,7 @@ const command_t COMMANDS[]= {"help", " Gives help on commands. Usage:\n\r help ;it lists all builtins\n\r help ;help on command\n\r", &cmd_help}, {"history", " Lists used commands\n\r", &cmd_history}, {"kill", " Stops a running process. Usage:\n\r kill \n\r kill all\n\r", &cmd_kill}, + {"pkill", " Kills all processes by name. Usage:\n\r pkill \n\r", &cmd_pkill}, {"ls", " Lists the files in a directory. Usage:\n\r ls ;lists the files in current directory\n\r ls ;lists the files at specified folder\n\r ls -1 ;lists the files in a single column\n\r", &cmd_ls}, {"mkdir", " Makes directory. Usage:\n\r mkdir ;creates the folder in working directory\n\r mkdir ;create folder by specified path\n\r", &cmd_mkdir}, {"more", " Displays a file data to the screen. Usage:\n\r more \n\r", &cmd_more}, diff --git a/programs/system/shell/locale/rus/globals.h b/programs/system/shell/locale/rus/globals.h index 9c430d8e7a..06332a3dcc 100644 --- a/programs/system/shell/locale/rus/globals.h +++ b/programs/system/shell/locale/rus/globals.h @@ -15,6 +15,7 @@ const command_t COMMANDS[]= {"help", " Справка по командам. Использование:\n\r help ;список всех команд\n\r help <команда> ;справка по команде\n\r", &cmd_help}, {"history", " Список использованных команд\n\r", &cmd_history}, {"kill", " Убивает процесс. Использование:\n\r kill \n\r kill all\n\r", &cmd_kill}, + {"pkill", " Убивает все процессы по имени. Использование:\n\r pkill <имя_процесса>\n\r", &cmd_pkill}, {"ls", " Выводит список файлов. Использование:\n\r ls ;список файлов в текущем каталоге\n\r ls <директория> ;список файлов из заданной директории\n\r", &cmd_ls}, {"mkdir", " Создает каталог. Использование:\n\r mkdir <имя папки> ;создать папку в текущем каталоге\n\r mkdir <путь><имя папки> ;создать папку по указанному пути\n\r", &cmd_mkdir}, {"more", " Выводит содержимое файла на экран. Использование:\n\r more <имя файла>\n\r", &cmd_more},