mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Add new os_kill
This commit is contained in:
parent
ac5191dafe
commit
8d1aabdb6b
3 changed files with 40 additions and 0 deletions
17
os/mingw.c
17
os/mingw.c
|
|
@ -2774,6 +2774,23 @@ int os_term(pid_t pid)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int os_kill(pid_t pid)
|
||||||
|
{
|
||||||
|
if (pid <= 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
HANDLE h = (void*)pid;
|
||||||
|
|
||||||
|
if (!TerminateProcess(h, 1)) {
|
||||||
|
windows_errno(GetLastError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int os_command(const char* command, const char* run_as_user, const char* stdin_text)
|
int os_command(const char* command, const char* run_as_user, const char* stdin_text)
|
||||||
{
|
{
|
||||||
wchar_t conv[CONV_MAX];
|
wchar_t conv[CONV_MAX];
|
||||||
|
|
|
||||||
7
os/os.h
7
os/os.h
|
|
@ -140,6 +140,13 @@ pid_t os_wait(pid_t pid, int* status);
|
||||||
*/
|
*/
|
||||||
int os_term(pid_t pid);
|
int os_term(pid_t pid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forcibly terminate a process.
|
||||||
|
* \param pid Process ID of the process to kill.
|
||||||
|
* \return 0 on success, -1 on failure.
|
||||||
|
*/
|
||||||
|
int os_kill(pid_t pid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fork and execute a verified executable, discarding all I/O.
|
* Fork and execute a verified executable, discarding all I/O.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
16
os/unix.c
16
os/unix.c
|
|
@ -1300,6 +1300,11 @@ int os_wait(pid_t pid, int* status)
|
||||||
|
|
||||||
int os_term(pid_t pid)
|
int os_term(pid_t pid)
|
||||||
{
|
{
|
||||||
|
if (pid <= 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send signal to the negative PID to target the entire Process Group.
|
* Send signal to the negative PID to target the entire Process Group.
|
||||||
* This ensures that SnapRAID and any programs it may have spawned are
|
* This ensures that SnapRAID and any programs it may have spawned are
|
||||||
|
|
@ -1308,6 +1313,17 @@ int os_term(pid_t pid)
|
||||||
return kill(-pid, SIGTERM);
|
return kill(-pid, SIGTERM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int os_kill(pid_t pid)
|
||||||
|
{
|
||||||
|
if (pid <= 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send SIGKILL signal to the negative PID to target the entire Process Group */
|
||||||
|
return kill(-pid, SIGKILL);
|
||||||
|
}
|
||||||
|
|
||||||
int os_spawn_and_wait(const char** argv)
|
int os_spawn_and_wait(const char** argv)
|
||||||
{
|
{
|
||||||
pid_t pid = os_spawn((char**)argv, 0, 0, 0);
|
pid_t pid = os_spawn((char**)argv, 0, 0, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue