Add waitpid and execve

This commit is contained in:
2026-01-17 15:19:52 -05:00
parent ea0ec6a818
commit 73ad441585
5 changed files with 249 additions and 153 deletions

View File

@@ -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