diff --git a/fun.h b/fun.h index 4092159..c1db301 100644 --- a/fun.h +++ b/fun.h @@ -1,15 +1,9 @@ #ifndef FUN_H_INCLUDED #define FUN_H_INCLUDED -#define MAXLINE (80) +#define MAXLINE (80) #include "fun_2.c" #include "fun_1.c" -//void history(char *cmdline); -//void print_his(char *argv); - -//void eval(char *cmdline); -//int parseline(const char *cmdline, char **argv); - #endif // FUN_H_INCLUDED diff --git a/fun_1.c b/fun_1.c index 1340cb8..c636f78 100644 --- a/fun_1.c +++ b/fun_1.c @@ -5,7 +5,11 @@ #include #include "mytop.c" -//#include "fun.h" + +int parseline(const char *cmdline, char **argv); +int builtin_cmd(char **argv); +int dup2(int fd, int arg); +int chdir(const char *path ); void eval(char *cmdline) { diff --git a/fun_2.c b/fun_2.c index b5fdeef..f8ef86e 100644 --- a/fun_2.c +++ b/fun_2.c @@ -1,7 +1,15 @@ #include -#include -//#include "fun.h" +#include + +void history(char *cmdline); +void print_his(char *argv); +int pipe(int *fd); +int fork(); +int close(int arg); +int dup(int fd); +int execvp(const char* command, char* argv[]); +int wait(int arg); static int num = 0; static char storage[MAXLINE][MAXLINE]; diff --git a/main b/main new file mode 100755 index 0000000..d28b99d Binary files /dev/null and b/main differ diff --git a/main.c b/main.c index 492057a..9b98d35 100644 --- a/main.c +++ b/main.c @@ -1,15 +1,11 @@ #include #include #include "fun.h" + +void eval(char *cmdline); +void sigint_handler(); +pid_t getpid(void); pid_t main_proc_pid; -void sigint_handler() -{ - pid_t pid = getpid(); - if(pid != main_proc_pid) - { - exit(0); - } -} int main() { @@ -26,4 +22,13 @@ int main() history(cmdline); } return 0; +} + +void sigint_handler() +{ + pid_t pid = getpid(); + if(pid != main_proc_pid) + { + exit(0); + } } \ No newline at end of file diff --git a/mytop.c b/mytop.c index c88cc73..0e3bf60 100644 --- a/mytop.c +++ b/mytop.c @@ -1,5 +1,4 @@ -//#define mytop_h #include #include #include @@ -313,13 +312,10 @@ void get_procs(void) void getkinfo(void) { FILE *fp; - if ((fp = fopen("/proc/kinfo", "r")) == NULL) { - exit(1); } - if (fscanf(fp, "%u %u", &nr_procs, &nr_tasks) != 2) { - + if (fscanf(fp, "%u %u", &nr_procs, &nr_tasks) != 2) { exit(1); } fclose(fp); @@ -338,4 +334,4 @@ void mytop() get_procs(); print_procs(prev_proc,proc,1); return; -} \ No newline at end of file +}