# HG changeset patch # User Markus Bröker # Date 1239878953 -7200 # Node ID 993b97c4ad2d5316603a89a916d3d617548ccbea # Parent 5a82f89d607ecbc3be7433e9d043d836574fe996 FORK ERROR in prog_limit and mem2swap: execve overrides the current PID committer: Markus Bröker diff --git a/.gitignore b/.gitignore new file mode 100644 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*~ +*.[oa] +*.so* +*.dll +*.bak +*.obj diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -290,6 +290,11 @@ .PHONY: clean uninstall clean: - rm -f *.o *~ + find -name '*~' -exec rm -f {} \; + find -name '*.[oa]' -exec rm -f {} \; rm -f $(TARGET) +beauty: + find -name '*.[ch]' -exec indent {} \; + find -name '*.[ch]' -exec eraser {} \; + @make clean diff --git a/mem2swap.c b/mem2swap.c --- a/mem2swap.c +++ b/mem2swap.c @@ -9,6 +9,7 @@ #include #include #include +#include #define N 1000 @@ -29,6 +30,7 @@ int size = sizeof (*p); int megs = DEFAULT_MEGS; + int pid; if (argc == 2) megs = atoi (argv[1]); @@ -64,7 +66,17 @@ } printf ("\n\n"); - execve ("/usr/bin/free", args, NULL); - return EXIT_SUCCESS; + pid = fork (); + switch (pid) { + case 0: + execve ("/usr/bin/free", args, NULL); + case -1: + perror ("Fork Error"); + return EXIT_FAILURE; + default: + wait (&pid); + } + + return pid; } diff --git a/parser/c_compiler/include/prototypes.h b/parser/c_compiler/include/prototypes.h --- a/parser/c_compiler/include/prototypes.h +++ b/parser/c_compiler/include/prototypes.h @@ -1,14 +1,13 @@ #ifndef PROTOTYPES_H #define PROTOTYPES_H -int yyparse(); -int yylex(); -void yyerror(char*); -int yywrap(); -int count(); -int check_type(); -void comment(); +int yyparse (); +int yylex (); +void yyerror (char *); +int yywrap (); +int count (); +int check_type (); +void comment (); #define YYSTYPE char* #endif - diff --git a/prog_limit.c b/prog_limit.c --- a/prog_limit.c +++ b/prog_limit.c @@ -5,6 +5,7 @@ #include #include +#include #include int set_limit (int); @@ -12,6 +13,7 @@ int main (int argc, char **argv) { int i; + int pid; char **args; @@ -31,11 +33,20 @@ args[i - 2] = NULL; - if (set_limit (atoi (argv[1])) == 0) { - i = execvp (argv[2], args); - } else { - perror ("Limit Error"); + pid = fork (); + switch (pid) { + case 0: + if (set_limit (atoi (argv[1])) == 0) { + i = execvp (argv[2], args); + } else { + perror ("Limit Error"); + return EXIT_FAILURE; + } + case -1: + perror ("Fork Error"); return EXIT_FAILURE; + default: + wait (&i); } if (args != NULL)