waitpid.c 497 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #ifndef __WIN32
  3. #include <stddef.h>
  4. #include <sys/wait.h>
  5. #include <errno.h>
  6. #include <sys/types.h>
  7. #include <unistd.h>
  8. #endif
  9. int bmx_system(const char * c) {
  10. #ifdef __WIN32
  11. return system(c);
  12. #else
  13. int status;
  14. pid_t pid = fork();
  15. if (pid == 0) {
  16. execl("/bin/sh", "/bin/sh", "-c", c, NULL);
  17. _exit(-1);
  18. } else if (pid < 0) {
  19. status = -1;
  20. } else {
  21. if (waitpid(pid, &status, 0) != pid) {
  22. status = -1;
  23. }
  24. }
  25. return status;
  26. #endif
  27. }