newlib: add test for waitpid (to implement)
This commit is contained in:
parent
d49ba60dcb
commit
690a89d3ce
|
@ -0,0 +1,43 @@
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
pid_t cpid, w;
|
||||||
|
int status;
|
||||||
|
|
||||||
|
|
||||||
|
cpid = fork();
|
||||||
|
if(cpid == -1){
|
||||||
|
perror("fork");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cpid == 0) { /* Code executed by child */
|
||||||
|
printf("Child PID is %ld\n", (long) getpid());
|
||||||
|
_exit(10);
|
||||||
|
}
|
||||||
|
/* Code executed by parent */
|
||||||
|
do {
|
||||||
|
w = waitpid(cpid, &status, WUNTRACED);
|
||||||
|
if (w == -1) {
|
||||||
|
perror("waitpid");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
printf("exited, status=%d\n", WEXITSTATUS(status));
|
||||||
|
} else if (WIFSIGNALED(status)) {
|
||||||
|
printf("killed by signal %d\n", WTERMSIG(status));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else if (WIFSTOPPED(status)) {
|
||||||
|
printf("stopped by signal %d\n", WSTOPSIG(status));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
|
}
|
|
@ -32,6 +32,7 @@
|
||||||
"SourceFilesCmd": [
|
"SourceFilesCmd": [
|
||||||
"000-hello.c",
|
"000-hello.c",
|
||||||
"010-fork.c",
|
"010-fork.c",
|
||||||
|
"020-waitpid.c",
|
||||||
"100-files.c",
|
"100-files.c",
|
||||||
"101-files.c",
|
"101-files.c",
|
||||||
"200-signals.c"
|
"200-signals.c"
|
||||||
|
|
Loading…
Reference in New Issue