Those approved by Access Center MUST take the exam at Access Center
Covered topics: 1. Reading List in class webpage: Chapters and sections covered 2. LAB Assignments: must review your LAB work!!! LAB1pre: Variables in C, stack usage; LAB1 : myprintf function, partitiion table LAB2pre: C sructures, Link list processing, binary tree PROC structure ksleep()/kwakeup() kfork(), kexit(), kwait() LAB2 : mysh program: fork-execve-exit-wait; I/O redirection, PIPE LAB3pre: threads, mutex lock LAB3: Gauss Elimination by threads FILE operations: mkdir, chdir, getcwd stat and ls program cat, cp programs system call vs Library I/O functions ========================== SAMPLEs ========================================= LAB1pre Part1: C variables in a.out file: READ Chapter 2.3.1, 2.3.2 Given a C program with GLOBAL variable, LOCAL variables, which variables are in a.out file?________________ WHY?_______________________________________ Stack contents: READ Chapter 2.4.1, 2.4.2, 2.4.3 Given main(int argc, char *argv[]){ int a=1,b=2; A(a,b); } int A(int x, int y){ int u, v; HERE: } Draw a diagram of stack contents from HERE: to argv of main() Identify the STACK FRAME of A() function. myprintf(char *fmt, . . .) { char *cp; int *ip; ....} Given printu(u32 x), Write code for printd(int x) ______________________ Write code to let cp point at the fmt string_______________________ Write code to let ip point at the first item to be printed on stack__________ Partition table: How did you get MBR of a virtual disk into char buf[512]? Write code to print the TYPE of partition 3 in MBR: What's an extended partition? Chapter 2.10: Link List Processing Write C statements to define a node structure containing: name : array of 64 chars key : int next : pointer to next node; Given a link list of NODEs as defined above, Write C code to print the names of the list elements. Write code to INSERT a new node to the END of a list Write code to delete a node with a given key value LAB2pre: What's a process? ______________________ What does ksleep() do?___________________ What does kwakeup() do?__________________ How does a process terminate? ___________ What does pid=wait(int *status) do?____________ Processes form a BINARY tree by child, sibling pointers. Assume: PROC *p kfork() a child *q. (1). Write code to insert q into CHILD list of p: _______________ (2). write code to print child list of p: ________________________ LAB#2: sh simulator <========== EXTREMELY IMPORTANT!!!! READ Chapter 3.8.1: fork() Chapter 3.8.3: Process termination Chpater 3.8.4: pid = wait(int *status) Chapter 3.8.6: execve() Chapter 3.9 : I/O redirection Chapter 3.10.2: Pipe command processing For any Linux command, how does Linux sh find the command?__________________ Write code to tokenize PATH into dir[0], dir[1],..._________________________ ASSUME: YOUR sh gets a command line = "cmd one two three" Wrtie C code to tokenize line into char *myargv[ ]. Write C code to execute cmd, passing as parameters myargv and env YOUR main sh's logic: while(1){ get a command line; tokenize the command line; for non-trivial command: fork a child (EXACT code): ______________________________________ if (parent){ wait for child to die: EXACT code:_________________ repeat while loop: EXACT code: ____________________ } else{ // CHILD sh do the command line } } ---------------------------------------------------------------- CHILD sh: for a command line = CMD a b c d > outfile Write code to do > outfile: ___________________________________________ MAY be < : Create a pathname = dir[i]/cmd: CODE: ________________________________ Create myargv[ ]: Show myargv[ ] EXACTLY: ___________________________ int r = execve(pathname, myargv, env); What if the execve() call succeeds? ________________________________ What if the execve() call fails? ___________________________________ Assume command line = cat filename | grep printf Write C code to do the pipe _____________________________________________ ========================================================================== Chapter 4: Concepts on Concurrent Programming Threads vs. Process: What are threads? How to create threads? _______________________ What does thread_join() do? _______________________ What's the difference between thread_barrier() and thread_join()? What's a Critical Region? _______________________ How to protect Critical Regions __________________ In Gauss elimination: What's partial pivoting? ________________________ Why partial pivoting? ________________________ Given linear equstions A.X = B What's LU decomposition? _______________________________________________ After converting A = L.U, how to solve for X? _________________________ ========================================================================== Chapter 7: File Operation Levels: Fle operation commands: mkdir, rmdir, cd, pwd, chmod Write down syscall function for each: ______ _____ _____ _____ _______ Chapter 8: System calls: stat and ls program: u16 st_mode: How to tell a file is REGular ? ______________________________ DIRectory? ______________________________ LNKfile ? ______________________________ u32 st_ctime = 12345678: what does the value mean? ________________________________________ How to convert st_ctime into CALENDAR form?_______________________ Write C code to print all the file names under Current Directory: ==================================================================== Chapter 9: Lib I/O Functions vs System calls. Write C code to open filename for READ: _________________ then read 10 bytes: _________________ fopen filename for READ: _________________ then read 10 bytes: _________________ Relation between fopen and open? ____________________________ fread and read? ____________________________ When to use syscall? when to use Lib I/O functions?