diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-05-24 17:08:04 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-05-24 17:08:04 +0200 |
commit | 922b46952d38f51850640a20d7be4747e84e95f4 (patch) | |
tree | cff5b0ddfde0f1fd6eaa9a95d960ebf4a85f9a19 /02_exercise/process.c | |
parent | 8f33ab3bf8b7d5a256c1d996e572fa67a5578b4f (diff) | |
download | betriebssysteme-922b46952d38f51850640a20d7be4747e84e95f4.tar.gz betriebssysteme-922b46952d38f51850640a20d7be4747e84e95f4.zip |
implemented a basic wait, not much tests yet, some functionality missing
Diffstat (limited to '02_exercise/process.c')
-rw-r--r-- | 02_exercise/process.c | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/02_exercise/process.c b/02_exercise/process.c index fb55236..95a0600 100644 --- a/02_exercise/process.c +++ b/02_exercise/process.c @@ -107,12 +107,6 @@ int parse_line(char const *const line, process **processes) { int exec_command(process p) { int status; - if (!p.blocking) { - // if the process is to be put in the background let a fork handle it - if (fork() != 0) - return 0; - } - if ((p.pid = fork()) == 0) { if (p.in_fd != 0) { dup2(p.in_fd, 0); @@ -146,16 +140,10 @@ int exec_command(process p) { if (!p.blocking) printf("[%i]\n", p.pid); - if (waitpid(p.pid, &status, 0) < 0) { + if (waitpid(p.pid, &status, p.blocking ? 0 : WNOHANG) < 0) { fprintf(stderr, "wait error'ed out\n"); } - if (!p.blocking) { - printf("[%i] TERMINATED\n", p.pid); - printf("[%i] EXIT STATUS: %i\n", p.pid, status); // TODO: exit status is wrong - exit(0); - } - return WEXITSTATUS(status); } |