main.c 651 B

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include <uv.h>
  3. uv_loop_t *loop;
  4. uv_process_t child_req;
  5. uv_process_options_t options;
  6. int main() {
  7. loop = uv_default_loop();
  8. char* args[3];
  9. args[0] = "sleep";
  10. args[1] = "100";
  11. args[2] = NULL;
  12. options.exit_cb = NULL;
  13. options.file = "sleep";
  14. options.args = args;
  15. options.flags = UV_PROCESS_DETACHED;
  16. int r;
  17. if ((r = uv_spawn(loop, &child_req, &options))) {
  18. fprintf(stderr, "%s\n", uv_strerror(r));
  19. return 1;
  20. }
  21. fprintf(stderr, "Launched sleep with PID %d\n", child_req.pid);
  22. uv_unref((uv_handle_t*) &child_req);
  23. return uv_run(loop, UV_RUN_DEFAULT);
  24. }