pid.c 778 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <reproc/drain.h>
  4. #include <reproc/reproc.h>
  5. #include "assert.h"
  6. int main(void)
  7. {
  8. const char *argv[] = { RESOURCE_DIRECTORY "/pid", NULL };
  9. char *output = NULL;
  10. reproc_sink sink = reproc_sink_string(&output);
  11. int r = -1;
  12. reproc_t *process = reproc_new();
  13. ASSERT(process);
  14. ASSERT(reproc_pid(process) == REPROC_EINVAL);
  15. r = reproc_start(process, argv, (reproc_options){ 0 });
  16. ASSERT_OK(r);
  17. r = reproc_drain(process, sink, sink);
  18. ASSERT_OK(r);
  19. ASSERT(output != NULL);
  20. ASSERT(reproc_pid(process) == strtol(output, NULL, 10));
  21. r = reproc_wait(process, REPROC_INFINITE);
  22. ASSERT_OK(r);
  23. ASSERT(reproc_pid(process) == strtol(output, NULL, 10));
  24. reproc_destroy(process);
  25. reproc_free(output);
  26. }