]> Devi Nivas Git - cs3210-lab0.git/commitdiff
Finish part 2
authorAdvaith Menon <noreply-git@bp4k.net>
Thu, 15 Jan 2026 13:33:10 +0000 (19:03 +0530)
committerAdvaith Menon <noreply-git@bp4k.net>
Thu, 15 Jan 2026 13:33:10 +0000 (19:03 +0530)
* Write forkexec program

user/include/user.h
user/src/lab0/forkexec.c

index 4f99c52ba6c2380d64453462fb276382351a9157..5e2f4889581597277ba63cfcbd94a33233200add 100644 (file)
@@ -34,6 +34,6 @@ void printf(int, const char*, ...);
 char* gets(char*, int max);
 uint strlen(const char*);
 void* memset(void*, int, uint);
-void* malloc(uint);
+void* malloc(uint); // umalloc.c
 void free(void*);
 int atoi(const char*);
index d98ecf9848b51f155a2d1c1971a9d857dfc81360..c7623438800dd1892cf4c5199252bb8de9690944 100644 (file)
@@ -2,10 +2,34 @@
 #include "stat.h"
 #include "user.h"
 
+#define _NULL 0
+#define STDOUT_FD 1
+
+
 int
 main(int argc, char *argv[])
 {
-  // Student code goes here
+    // int i;
+
+    int pid = fork();
+    if (pid == 0) {
+        /* argv ends with a null ptr so no need for any malloc drama */
+        //char **child_argv = malloc((argc + 1) * sizeof(char *));
+
+
+        //for (i = 0; i < argc; ++i)
+        //    child_argv[i] = argv[i]; /* point to same thing */
+
+        //child_argv[argc] = _NULL;
+
+        /* let's exec */
+        exec("echo", argv);
+        /* for old approach: argv memory should anyway be freed when process
+         * dies */
+    } else {
+        wait();
+        // printf(STDOUT_FD, "The child PID was: %d\n", pid);
+    }
 
-  exit();
-}
\ No newline at end of file
+    exit();
+}