{ "q1": { "type": "blank", "question": "\n
On a typical Unix system, we are presented with two key storage\nabstractions. The first is the (1) ____, which is just a linear\narray of bytes that you can (2) ____ or (3) ____. Associated\nwith each of these is an (4) ____ number, which is its low-level\nname.
\n\nThe second abstraction is the (5) ____, which is a list of pairs\ncontaining the user-readable name of the data, and its assocated low-level\nidentifier.
\n" }, "q3": { "type": "blank", "question": "\nIdentify the key system call you should use to implement the\nfollowing Unix command-line utility:
\n\n\n
Identify the system call you should use to accomplish the\nfollowing tasks:
\n\n\n
Fill in the blanks for the following program: walk.c
\n\n
\n/* walk.c */\n\n#include\n\n\n#include \n#include \n#include \n\n#include \n#include \n#include \n\nint main(int argc, char *argv[]) {\n /* Open directory handle */\n DIR *d = ____(\".\"); /* 1 */\n if (!d) {\n fprintf(stderr, \"%s\\n\", ____(errno)); /* 2 */\n return EXIT_FAILURE;\n }\n\n /* For each directory entry, check if it is a file, and print out the its\n * name and file size */\n for (struct dirent *e = ____(d); e; e = ____(d)) { /* 3 & 4 */\n /* Skip current directory and parent directory */\n if (strcmp(____, \".\") == 0 || strcmp(____, \"..\") == 0) { /* 5 & 6 */\n continue;\n }\n\n /* Skip non-regular files */\n if (____ != DT_REG) { /* 7 */\n continue;\n }\n\n /* Get file meta-data */\n struct stat s;\n if (____(____, &s) < 0) { /* 8 & 9 */\n fprintf(stderr, \"%s\\n\", ____(errno)); /* 10 */\n continue;\n }\n\n /* Display file name and size */\n printf(\"%s %lu\\n\", ____, ____); /* 11 & 12 */\n }\n\n /* Close directory handle */\n ____(d); /* 13 */\n return EXIT_SUCCESS;\n}\n
Note, that this program performs the equivalent of the following Python code:
\n\n\nimport os\n\nfor name in os.listdir('.'):\n if os.path.isfile(name):\n print(name, os.path.getsize(name))\n\n\n
Your program should display something like this:
\n\n\nwalk.c 1161\nwalk 22896\nMakefile 565\nREADME.md 22\nwalk.py 136\n\n" } }