pish/src/Pish.c

43 lines
847 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
char* getcmd(void)
{
;
}
// Dummy function for Pish to run
void exec(char* command)
{
;
}
void Pish(void)
{
while (1)
{
char *cmd = getcmd();
int retval = fork();
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?
exec(cmd);
// exec does not return if it succeeds
printf("ERROR: Could not execute %s\n", cmd);
exit(1);
} else {
// This is the parent process; Wait for the child to finish
int pid = retval;
wait(pid);
}
}
}