#define PGSIZE 4096 // 4K Page size
#define CURRENTLY_OCCUPIED_MEM 0
+#define CURRENTLY_OPEN_PROCESSES 2
#define STDOUT_FD 1
+static void test_maxmem(void);
+static void test_maxfd(void);
+static void test_maxproc(void);
+static void forkfun(void (*) (void));
+
+
int
main(int argc, char *argv[])
{
// Student code goes here
+ /* Global gameplan: Since this deals with exhaustion of resources and
+ * resources won't be freed till the process dies, we should do these in
+ * subprocesses. */
+
+ forkfun(&test_maxmem);
+ forkfun(&test_maxfd);
+ test_maxproc(); /* I deal with exiting */
+
+
+}
+
+
+void test_maxmem(void) {
int memsz;
/* initialize to current memory */
memsz += PGSIZE;
printf(STDOUT_FD, "Maximum Memory Size: 0x%x\n", memsz);
+}
+
+void test_maxfd(void) {
/* Extra Credit: Max no of file descriptors */
/* Game Plan: File descriptors are allocated sequentially, as we know this
* from the xv6 book's explanation on replacing stdin/stdout. We shall keep
// poc validated
// printf(STDOUT_FD, "Maximum Number of Files Open at Once: %d\n",
// manual_tally);
+}
+
+void forkfun(void (*fun) (void)) {
+ /* fork function */
+
+ int pid = fork();
+
+ if (pid > 0) {
+ /* wait till child finishes */
+ wait();
+ } else {
+ /* "exec" the child */
+ fun();
+ exit();
+ }
+}
+
+void test_maxproc(void) {
+ /* Extra Credit: Max. no of processes */
+ /* This one is just creating a fork bomb. */
+ /* So PIDs don't seem to be reused hence TBC */
+ int max_procs, fpid;
+
+ max_procs = CURRENTLY_OPEN_PROCESSES; /* 1 for the shell and 1 for me */
+
+ while ((fpid = fork()) != -1)
+ if (fpid != 0) {wait(); exit(); } /* parents wait, then exit */
+ else ++max_procs;
+
+ /* these executed by the last child of the fork bomb */
+ printf(STDOUT_FD, "Maximum Number of Processes: %d\n", max_procs);
+ // printf(STDOUT_FD, "fpid is: %d\n", fpid);
exit();
}