| 441 | } |
| 442 | |
| 443 | static int ProcessKill(pid_t pid, int signum) |
| 444 | { |
| 445 | Dictionary::Ptr request = new Dictionary({ |
| 446 | { "command", "kill" }, |
| 447 | { "pid", pid }, |
| 448 | { "signum", signum } |
| 449 | }); |
| 450 | |
| 451 | String jrequest = JsonEncode(request); |
| 452 | size_t length = jrequest.GetLength(); |
| 453 | |
| 454 | std::unique_lock<std::mutex> lock(l_ProcessControlMutex); |
| 455 | |
| 456 | do { |
| 457 | while (send(l_ProcessControlFD, &length, sizeof(length), 0) < 0) { |
| 458 | StartSpawnProcessHelper(); |
| 459 | } |
| 460 | } while (send(l_ProcessControlFD, jrequest.CStr(), jrequest.GetLength(), 0) < 0); |
| 461 | |
| 462 | char buf[4096]; |
| 463 | |
| 464 | ssize_t rc = recv(l_ProcessControlFD, buf, sizeof(buf), 0); |
| 465 | |
| 466 | if (rc <= 0) |
| 467 | return -1; |
| 468 | |
| 469 | String jresponse = String(buf, buf + rc); |
| 470 | |
| 471 | Dictionary::Ptr response = JsonDecode(jresponse); |
| 472 | return response->Get("errno"); |
| 473 | } |
| 474 | |
| 475 | static int ProcessWaitPID(pid_t pid, int *status) |
| 476 | { |