2015-07-22 21:32:54 +03:00
|
|
|
#ifndef INCLUDE_RESTART_PROCESS_H
|
|
|
|
#define INCLUDE_RESTART_PROCESS_H
|
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
2015-03-25 14:46:22 +03:00
|
|
|
enum {
|
|
|
|
MULTIPLE,
|
|
|
|
SINGLE
|
|
|
|
};
|
|
|
|
|
2016-11-14 03:42:32 +03:00
|
|
|
#define MAX_PROCESS_COUNT 256
|
|
|
|
|
2018-10-04 20:53:33 +03:00
|
|
|
:bool CheckProcessExists(dword proc_name) {
|
2015-07-29 18:37:34 +03:00
|
|
|
int i;
|
|
|
|
proc_info Process;
|
2016-11-14 03:42:32 +03:00
|
|
|
for (i=0; i<MAX_PROCESS_COUNT; i++;)
|
2015-07-29 18:37:34 +03:00
|
|
|
{
|
|
|
|
GetProcessInfo(#Process, i);
|
|
|
|
if (strcmpi(#Process.name, proc_name)==0) return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
:void KillProcessByName(dword proc_name, byte multiple) {
|
2015-03-25 14:46:22 +03:00
|
|
|
int i;
|
|
|
|
proc_info Process;
|
2016-11-14 03:42:32 +03:00
|
|
|
for (i=0; i<MAX_PROCESS_COUNT; i++;)
|
2015-03-25 14:46:22 +03:00
|
|
|
{
|
|
|
|
GetProcessInfo(#Process, i);
|
|
|
|
if (strcmpi(#Process.name, proc_name)==0)
|
|
|
|
{
|
|
|
|
KillProcess(Process.ID);
|
|
|
|
if (multiple==SINGLE) break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-29 18:37:34 +03:00
|
|
|
}
|
|
|
|
|
2020-05-12 02:02:41 +03:00
|
|
|
:int GetProcessesCount(dword proc_name) {
|
|
|
|
int i, count=0;
|
|
|
|
proc_info Process;
|
|
|
|
for (i=0; i<MAX_PROCESS_COUNT; i++;)
|
|
|
|
{
|
|
|
|
GetProcessInfo(#Process, i);
|
|
|
|
if (strcmpi(#Process.name, proc_name)==0) count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2015-07-29 18:37:34 +03:00
|
|
|
:void RestartProcessByName(dword proc_name, byte multiple) {
|
2019-05-14 16:07:29 +03:00
|
|
|
KillProcessByName(proc_name + strrchr(proc_name, '/'), multiple);
|
2015-03-25 14:46:22 +03:00
|
|
|
RunProgram(proc_name, "");
|
2015-07-22 21:32:54 +03:00
|
|
|
}
|
|
|
|
|
2020-05-31 17:37:09 +03:00
|
|
|
:void RestartAllProcess() {
|
|
|
|
int i;
|
|
|
|
proc_info Process, Self;
|
|
|
|
GetProcessInfo(#Self, -1);
|
|
|
|
for (i=0; i<MAX_PROCESS_COUNT; i++;)
|
|
|
|
{
|
|
|
|
GetProcessInfo(#Process, i);
|
|
|
|
if (Process.name)
|
|
|
|
&& (!streq(#Process.name, "OS"))
|
|
|
|
&& (Process.ID != Self.ID)
|
|
|
|
KillProcess(Process.ID);
|
|
|
|
}
|
|
|
|
RunProgram("/sys/launcher", NULL);
|
|
|
|
}
|
2015-07-29 18:37:34 +03:00
|
|
|
|
2015-07-22 21:32:54 +03:00
|
|
|
#endif
|