From: Advaith Menon Date: Thu, 15 Jan 2026 14:08:38 +0000 (+0530) Subject: EC part 5 X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=675067e5249390205ae453ac0d5d01299c6435c1;p=cs3210-lab0.git EC part 5 --- diff --git a/user/src/lab0/limits.c b/user/src/lab0/limits.c index 745f205..837b00d 100644 --- a/user/src/lab0/limits.c +++ b/user/src/lab0/limits.c @@ -22,5 +22,30 @@ main(int argc, char *argv[]) printf(STDOUT_FD, "Maximum Memory Size: 0x%x\n", memsz); + /* 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 + * track of the current and last file descriptor and keep on duplicating an + * existing file until dup returns -1. + * + * To prove that this works, I'll also keep a manual file counter and ensure + * they match. + */ + int curfd, prevfd; + // int manual_tally; + + // POC verified + // manual_tally = 3; + + curfd = 2; /* because stderr. Only used if first dup fails. */ + + while ((prevfd = curfd) && (curfd = dup(0)) >= 0); + // ++manual_tally; + + printf(STDOUT_FD, "Maximum Number of Files Open at Once: %d\n", + prevfd + 1); // remember first valid descriptor is 0 + // poc validated + // printf(STDOUT_FD, "Maximum Number of Files Open at Once: %d\n", + // manual_tally); exit(); }