streams-test.c 837 B

123456789101112131415161718192021222324252627282930313233343536
  1. // This is an open source non-commercial project. Dear PVS-Studio, please check
  2. // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
  3. /// Helper program to exit and keep stdout open (like "xclip -i -loops 1").
  4. #include <stdio.h>
  5. #include <uv.h>
  6. int main(int argc, char **argv)
  7. {
  8. uv_loop_t *loop = uv_default_loop();
  9. uv_process_t child_req;
  10. char * args[3];
  11. args[0] = "sleep";
  12. args[1] = "10";
  13. args[2] = NULL;
  14. uv_process_options_t options = {
  15. .exit_cb = NULL,
  16. .file = "sleep",
  17. .args = args,
  18. .flags = UV_PROCESS_DETACHED,
  19. };
  20. int r;
  21. if ((r = uv_spawn(loop, &child_req, &options))) {
  22. fprintf(stderr, "%s\n", uv_strerror(r));
  23. return 1;
  24. }
  25. fprintf(stderr, "pid: %d\n", child_req.pid);
  26. uv_unref((uv_handle_t *)&child_req);
  27. return uv_run(loop, UV_RUN_DEFAULT);
  28. }