pish/src/Pish.c

47 lines
914 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include "Pish.h"
// Dummy function for Pish to run
2022-10-19 21:14:59 -05:00
char* getInput(void)
{
;
}
// Dummy function for Pish to run
void exec(char* command)
{
;
}
void Pish(void)
{
while (1)
{
2022-10-19 21:14:59 -05:00
char* command = getInput();
int retval = fork();
2022-10-19 21:14:59 -05:00
// Child
if (retval == 0)
{
// This is the child process
// Setup the child's process environment here
// E.g., where is standard I/O, how to handle signals?
2022-10-19 21:14:59 -05:00
exec(command);
// exec does not return if it succeeds
2022-10-19 21:14:59 -05:00
printf("ERROR: Could not execute %s\n", command);
exit(1);
2022-10-19 21:14:59 -05:00
}
// Parent
else
{
// This is the parent process; Wait for the child to finish
int pid = retval;
wait(pid);
}
}
}