wait-process.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Waiting for a subprocess to finish.
  2. Copyright (C) 2001-2003, 2006, 2008-2013 Free Software Foundation, Inc.
  3. Written by Bruno Haible <haible@clisp.cons.org>, 2001.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef _WAIT_PROCESS_H
  15. #define _WAIT_PROCESS_H
  16. /* Get pid_t. */
  17. #include <stdlib.h>
  18. #include <unistd.h>
  19. #include <sys/types.h>
  20. #include <stdbool.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Wait for a subprocess to finish. Return its exit code.
  25. If it didn't terminate correctly, exit if exit_on_error is true, otherwise
  26. return 127.
  27. Arguments:
  28. - child is the pid of the subprocess.
  29. - progname is the name of the program executed by the subprocess, used for
  30. error messages.
  31. - If ignore_sigpipe is true, consider a subprocess termination due to
  32. SIGPIPE as equivalent to a success. This is suitable for processes whose
  33. only purpose is to write to standard output. This flag can be safely set
  34. to false when the process' standard output is known to go to DEV_NULL.
  35. - If null_stderr is true, the usual error message to stderr will be omitted.
  36. This is suitable when the subprocess does not fulfill an important task.
  37. - slave_process should be set to true if the process has been launched as a
  38. slave process.
  39. - If exit_on_error is true, any error will cause the main process to exit
  40. with an error status.
  41. - If termsigp is not NULL: *termsig will be set to the signal that
  42. terminated the subprocess (if supported by the platform: not on native
  43. Windows platforms), otherwise 0, and the error message about the signal
  44. that terminated the subprocess will be omitted.
  45. Prerequisites: The signal handler for SIGCHLD should not be set to SIG_IGN,
  46. otherwise this function will not work. */
  47. extern int wait_subprocess (pid_t child, const char *progname,
  48. bool ignore_sigpipe, bool null_stderr,
  49. bool slave_process, bool exit_on_error,
  50. int *termsigp);
  51. /* Register a subprocess as being a slave process. This means that the
  52. subprocess will be terminated when its creator receives a catchable fatal
  53. signal or exits normally. Registration ends when wait_subprocess()
  54. notices that the subprocess has exited. */
  55. extern void register_slave_subprocess (pid_t child);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* _WAIT_PROCESS_H */