exec-sparse.c 538 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * exec-sparse
  3. *
  4. * this creates a child process to run "sparse"
  5. *
  6. * relies on fork, _exit, stdout and stderr, and execv
  7. *
  8. */
  9. #include <unistd.h>
  10. #include <err.h>
  11. static char *spargv[2] = { (char *)"sparse", NULL };
  12. static
  13. void
  14. spawnv(const char *prog, char **argv)
  15. {
  16. pid_t pid = fork();
  17. switch (pid) {
  18. case -1:
  19. err(1, "fork");
  20. case 0:
  21. /* child */
  22. execv(prog, argv);
  23. err(1, "%s", prog);
  24. default:
  25. /* parent */
  26. break;
  27. }
  28. }
  29. int
  30. main()
  31. {
  32. spawnv("/uw-testbin/sparse", spargv);
  33. return 0;
  34. }