Use posix_spawn and wait4 in libc

This commit is contained in:
Tate, Hongliang Tian 2019-01-06 19:42:36 +08:00
parent c00fddd2bf
commit 98b4508a0d

@ -1,19 +1,21 @@
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <spawn.h>
int main(void) {
int ret, child_pid, status;
printf("Run a parent process has pid = %d and ppid = %d\n", getpid(), getppid());
ret = syscall(__NR_spawn, &child_pid, "getpid/bin.encrypted", NULL, NULL);
ret = posix_spawn(&child_pid, "getpid/bin.encrypted", NULL, NULL, NULL, NULL);
if (ret < 0) {
printf("ERROR: failed to spawn a child process\n");
return -1;
}
printf("Spawn a new proces successfully (pid = %d)\n", child_pid);
ret = syscall(__NR_wait4, -1, &status, 0);
ret = wait4(-1, &status, 0, NULL);
if (ret < 0) {
printf("ERROR: failed to wait4 the child process\n");
return -1;