Add waitpid and execve
This commit is contained in:
22
buildtest.c
22
buildtest.c
@@ -34,10 +34,24 @@ int main(int argc, char* argv[]) {
|
||||
uint64_t pid = fork();
|
||||
// Print the pid in hex
|
||||
printhex(pid);
|
||||
|
||||
// Child process exits
|
||||
if(pid == 0) return 0;
|
||||
//TODO: wait on child to remove zombie process
|
||||
// Child process
|
||||
if (pid == 0) {
|
||||
const char *progname = "/bin/sh";
|
||||
const char *argv[4] = {
|
||||
progname,
|
||||
"-c",
|
||||
"echo hi from sh",
|
||||
0,
|
||||
};
|
||||
const char **envp = {0};
|
||||
int32_t err = execve(progname, argv, envp);
|
||||
// return with error code if execve fails
|
||||
return err;
|
||||
}
|
||||
int status; // Note: this is not JUST the exit code of the child
|
||||
waitpid(pid, &status, 0);
|
||||
print("Child wstatus: ");
|
||||
printhex((uint64_t)status);
|
||||
|
||||
// Test the read syscall
|
||||
#define INPUT_BUFFER_LEN 4096
|
||||
|
||||
Reference in New Issue
Block a user