Added base Pish from slides and fixed Makefile
This commit is contained in:
parent
e314d06c21
commit
31b5a5cbb5
2
Makefile
2
Makefile
@ -7,7 +7,7 @@ main:
|
||||
gcc $(INC) -c -o build/Pish.o src/Pish.c
|
||||
|
||||
exec:
|
||||
gcc -o bin/pish build/*.o
|
||||
gcc -o bin/pish.out build/*.o
|
||||
|
||||
clean:
|
||||
rm build/*
|
||||
|
0
include/.keep
Normal file
0
include/.keep
Normal file
8
include/Pish.h
Normal file
8
include/Pish.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef PISH_H
|
||||
#define PISH_H
|
||||
|
||||
char* getcmd(void);
|
||||
void exec(char* command);
|
||||
void Pish(void);
|
||||
|
||||
#endif
|
42
src/Pish.c
Normal file
42
src/Pish.c
Normal file
@ -0,0 +1,42 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include "Pish.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello world\n");
|
||||
Pish();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user