streams-test.c 674 B

1234567891011121314151617181920212223242526272829303132
  1. /// Helper program to exit and keep stdout open (like "xclip -i -loops 1").
  2. #include <stdio.h>
  3. #include <uv.h>
  4. int main(int argc, char **argv)
  5. {
  6. uv_loop_t *loop = uv_default_loop();
  7. uv_process_t child_req;
  8. char *args[3];
  9. args[0] = "sleep";
  10. args[1] = "10";
  11. args[2] = NULL;
  12. uv_process_options_t options = {
  13. .exit_cb = NULL,
  14. .file = "sleep",
  15. .args = args,
  16. .flags = UV_PROCESS_DETACHED,
  17. };
  18. int r;
  19. if ((r = uv_spawn(loop, &child_req, &options))) {
  20. fprintf(stderr, "%s\n", uv_strerror(r));
  21. return 1;
  22. }
  23. fprintf(stderr, "pid: %d\n", child_req.pid);
  24. uv_unref((uv_handle_t *)&child_req);
  25. return uv_run(loop, UV_RUN_DEFAULT);
  26. }