cproc.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef __GWS__cproc_h__
  2. #define __GWS__cproc_h__
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <sys/prctl.h>
  6. #include <pty.h>
  7. #include <fcntl.h>
  8. #include <sys/wait.h>
  9. #include "strlist.h"
  10. struct child_process_info {
  11. int pid;
  12. char state; // 'q'ueued, 'r'unning, 'd'ead
  13. int exit_status;
  14. int pty;
  15. int child_stdin;
  16. int child_stdout;
  17. int child_stderr;
  18. FILE* f_stdin;
  19. FILE* f_stdout;
  20. FILE* f_stderr;
  21. char* output_buffer;
  22. size_t buf_alloc;
  23. size_t buf_len;
  24. };
  25. struct job {
  26. int type; // c = child process, f = function
  27. volatile int state;
  28. union {
  29. int (*fn)(void*);
  30. char* cmd;
  31. };
  32. union {
  33. struct child_process_info* cpi;
  34. void* user_data;
  35. };
  36. };
  37. struct child_process_info* exec_cmdline_pipe(char* cmdline);
  38. struct child_process_info* exec_process_pipe(char* exec_path, char* args[]);
  39. int execute_mt(strlist* cmds, int threads, struct child_process_info*** cpis);
  40. void free_cpi(struct child_process_info* cpi, char freeOB);
  41. void read_cpi(struct child_process_info* cpi);
  42. #endif // __GWS__cproc_h__