UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus APRIL 2012 EXAMINATIONS

Similar documents
Question 1. Part (a) Part (b) Part (c) Part (d) Part (e) Part (f) APRIL 2012 Final Examination Solutions CSC 209H1S

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus DECEMBER 2017 EXAMINATIONS. CSC 209H1F Liu, Reid 3 hours. No Examination Aids

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus APRIL 2016 EXAMINATIONS. CSC 209H1S Michelle Craig, David Liu 3 hours

UNIVERSITY OF TORONTO Faculty of Arts and Science. St. George Campus APRIL 2017 EXAMINATIONS. CSC 209H1S Instructor: Karen Reid Duration: 3 hours

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 7

[6 marks] All parts of this question assume the following C statement. Parts (b) through (e) assume a variable called ptrs.

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 6

Student Number: Instructor: Reid Section: L0101 (10:10-11:00am)

CSC209H1S Day Midterm Solutions Winter 2010

Student Number: Instructor: Reid Section: L0201 (12:10-1:00pm)

COMP 2355 Introduction to Systems Programming

Student Number: Instructor: Reid Section: L5101 (6:10-7:00pm)

Process Creation in UNIX

UNIVERSITY OF TORONTO SCARBOROUGH Computer and Mathematical Sciences. APRIL 2016 EXAMINATIONS CSCB09H3S Software Tools & Systems Programming

CSC209F Midterm (L0101) Fall 1999 University of Toronto Department of Computer Science

CSE 333 SECTION 3. POSIX I/O Functions

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSE 333 SECTION 3. POSIX I/O Functions

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

CSC209F Midterm (L5101) Fall 1998 University of Toronto Department of Computer Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CSC209F Midterm (L0101) Fall 1998 University of Toronto Department of Computer Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Operating System Labs. Yuanbin Wu

UNIX System Calls. Sys Calls versus Library Func

Process Management! Goals of this Lecture!

Outline. OS Interface to Devices. System Input/Output. CSCI 4061 Introduction to Operating Systems. System I/O and Files. Instructor: Abhishek Chandra

The Shell, System Calls, Processes, and Basic Inter-Process Communication

Good Luck! Marking Guide. APRIL 2014 Final Exam CSC 209H5S

Group-A Assignment No. 6

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Student Number: Lab day, time: Instructor: Bianca Schroeder

structs as arguments

CSC209 Review. Yeah! We made it!

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

Week 13. Final exam review

Recitation 8: Tshlab + VM

Oral. Total. Dated Sign (2) (5) (3) (2)

CS354 gdb Tutorial Written by Chris Feilbach

Assignment clarifications

Signals. CSC209: Software Tools and Systems Programming. Furkan Alaca & Paul Vrbik

15-213/ Final Exam Notes Sheet Spring 2013!

CS240: Programming in C

ECE 650 Systems Programming & Engineering. Spring 2018

TCP: Three-way handshake

CSC209H Lecture 8. Dan Zingaro. March 4, 2015

CS 25200: Systems Programming. Lecture 14: Files, Fork, and Pipes

Processes. Processes (cont d)

Shells and Shell Programming

Pointers about pointers. Announcements. Pointer type. Example

Inter-process communication (IPC)

Lecture 3. Introduction to Unix Systems Programming: Unix File I/O System Calls

CS360 Midterm 2 Spring, 2016 James S. Plank March 10, 2016

10. I/O System Library

Workshop on Inter Process Communication Solutions

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

SOFTWARE ARCHITECTURE 3. SHELL

Section 3: File I/O, JSON, Generics. Meghan Cowan

Process Management! Goals of this Lecture!

Preview. Interprocess Communication with Pipe. Pipe from the Parent to the child Pipe from the child to the parent FIFO popen() with r Popen() with w

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Pipes and FIFOs. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Creating a Shell or Command Interperter Program CSCI411 Lab

Final Exam. Fall Semester 2016 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Unix File and I/O. Outline. Storing Information. File Systems. (USP Chapters 4 and 5) Instructor: Dr. Tongping Liu

Operating System Labs. Yuanbin Wu

CS 470 Operating Systems Spring 2013 Shell Project

Socket Programming for TCP and UDP

everything is a file main.c a.out /dev/sda1 /dev/tty2 /proc/cpuinfo file descriptor int

Process Management 1

File Descriptors and Piping

Linux Signals and Daemons

CSCI 2132 Final Exam Solutions

// socket for establishing connections

Shells and Shell Programming

Chapter 5. TCP Client-Server

CSE 333 Section 8 - Client-Side Networking

Introduction to Socket Programming

A. Basic Function Calls for Network Communications

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

OS COMPONENTS OVERVIEW OF UNIX FILE I/O. CS124 Operating Systems Fall , Lecture 2

Computer Science 330 Operating Systems Siena College Spring Lab 5: Unix Systems Programming Due: 4:00 PM, Wednesday, February 29, 2012

bash, part 3 Chris GauthierDickey

CSMC 412. Computer Networks Prof. Ashok K Agrawala Ashok Agrawala Set 2. September 15 CMSC417 Set 2 1

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

STUDY OF SOCKET PROGRAMMING

Lesson 2. process id = 1000 text data i = 5 pid = 1200

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

Shells & Shell Programming (Part B)

25.2 Opening and Closing a File

Jacobs University Bremen February 7 th, 2017 Dr. Kinga Lipskoch. Practice Sheet. First Name:... Last Name:... Matriculation Number:...

Contents. IPC (Inter-Process Communication) Representation of open files in kernel I/O redirection Anonymous Pipe Named Pipe (FIFO)

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

System Programming. Sockets

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

CSE 124 Discussion Section Sockets Programming 10/10/17

Transcription:

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science St. George Campus APRIL 2012 EXAMINATIONS CSC 209H1S Instructors Michelle Craig and Karen Reid Duration 3 hours PLEASE HAND IN Examination Aids: One double-sided 8.5x11 sheet of paper. No electronic aids. Student Number: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have received the signal to start. (In the meantime, please fill out the identification section above, and read the instructions below carefully.) Marking Guide # 1: / 8 This final examination consists of 8 questions on 22 pages. A mark of 30 out of 77 on this exam is required to pass this course. When you receive the signal to start, please make sure that your copy of the examination is complete. You are not required to add any #include lines, and unless otherwise specified, you may assume a reasonable maximum for character arrays or other structures. For shell programs, you do not need to include the #!/bin/sh. # 2: /10 # 3: /10 # 4: / 8 # 5: /17 # 6: / 8 # 7: / 5 # 8: /11 Good Luck! TOTAL: /77 Page 1

CSC 209H1S Final Examination APRIL 2012 Question 1. [8 marks] All of the code fragments below compile but many of them have something wrong. Check the appropriate box to indicate whether or not there is a problem and provide an explanation. There are no marks for checking something is wrong without an explanation. Part (a) char city[7] = "Toronto"; Something is wrong It is fine Part (b) int * p; *p = 12; Something is wrong It is fine Part (c) char * hobby = "running"; hobby[0] = "s"; Something is wrong It is fine Part (d) char fullname[30] = "Frederick"; fullname[4] = \0 ; Something is wrong It is fine Page 2 of 22

APRIL 2012 Final Examination CSC 209H1S Part (e) char postal[6] = "M4A"; strncat(postal, "3K5", 4); Something is wrong It is fine Part (f) int j; int x[5] = {4,2,7,8,9; for (j = 0; j <= 5; j++) { fprintf("%d\n", x[j]); Something is wrong It is fine Part (g) char class[7] = "CSC209"; class[6] = "H"; int i = strlen(class); Something is wrong It is fine Part (h) double average(int * a) { int i; double sum; for (i = 0; i < sizeof(a); i++ ) { sum += a[i]; return sum / sizeof(a); Something is wrong It is fine Page 3 of 22

CSC 209H1S Final Examination APRIL 2012 Question 2. [10 marks] All the subquestions below concern this Makefile. all: compile test Makefile compile: prog1 prog2 prog1 : prog1.o tree.o gcc ${FLAGS -o prog1 prog1.o tree.o prog2 : prog2.o tree.o gcc ${FLAGS -o prog2 prog2.o tree.o test: prog1 prog2 prog1 inputfile > prog1.out prog2 inputfile > prog2.out %.o : %.c tree.h gcc ${FLAGS -c $< The subquestions must be evaluated in order. The state of the files for one question sometimes depends on the previous question. You may assume that all compilations are successful. Part (a) In the Makefile the lines for compiling files work correctly even though the variable FLAGS is not defined inside Makefile. Give one reason why. Part (b) We compiled prog1 using this Makefile and then tried to use gdb on the executable. It did not work. What needs to be changed in the Makefile to fix the problem? Part (c) Suppose you have only the files prog1.c, prog2.c, tree.c, tree.h and inputfile in the same directory with Makefile. Which files, if any, are created, deleted, or modified when you call make prog1? Page 4 of 22

APRIL 2012 Final Examination CSC 209H1S Part (d) Which files, if any, are created, deleted, or modified if you call make prog1 immediately again? Why? Part (e) Which files, if any, are created, deleted, or modified if you next call make compile? Part (f) In the box below, write a rule for a clean target that will remove all.o files, all executables and any output files created by using this Makefile. Part (g) Suppose you now run make clean followed by make all. What files do you now have in the directory? You do not need to list the original.c or.h files Page 5 of 22

CSC 209H1S Final Examination APRIL 2012 Part (h) [3 marks] In the Makefile above, the test rule only creates the two output files. In the box below, write additional actions to append to this rule so that it compares the two output files. If they are identical, it should print the message test passes to stdout. If they are not identical, it should print the message Failed test: prog1.out does not match prog2.out to standard error. test: prog1 prog2 prog1 inputfile > prog1.out prog2 inputfile > prog2.out Page 6 of 22

APRIL 2012 Final Examination CSC 209H1S Question 3. [10 marks] You have a program foo that prints to standard output and standard error and also has a meaningful return value. Part (a) [2 marks] Give shell command(s) to call foo, ignoring its return value and saving its standard output into the variable Y, and leaving standard error printing to the screen. Part (b) [3 marks] Give shell command(s) to call foo, ignoring its standard output and standard error (so that it doesn t appear on the screen) and saving the return value in the variable X. Part (c) [2 marks] Show how to call foo, sending its standard output to the program wc, sending the standard error to the file foo.err and ignoring the return value. Part (d) [3 marks] A program called myclient uses the USER environment variable to identify the user, and takes an arbitrary number of arguments. You would like to test myclient with different values for the USER environment variable. Write a shell program, test myclient that takes a user name to store in USER as the first argument. The remaining arguments are arguments for myclient. test myclient will set the USER environment variable and then call myclient with the correct set of arguments. Page 7 of 22

CSC 209H1S Final Examination APRIL 2012 Question 4. [8 marks] Below are four versions of a function set to default which is intended to be called as follows: char ** names; set_to_default(names, "Unknown", 4); /* create an array of 4 names all set to "Unknown" */ /* OTHER CODE */ All of the implementations compile. Some of them may work, some may not. Some may work but the design choices restrict how the calling code can use names. For each subquestion, check one box indicating how the implementation will work in the context of the whole program. Then explain your answer paying particular attention to the restrictions that would be placed on the actions in the OTHER CODE statements in the calling function. Part (a) [2 marks] void set_to_default(char **names, char *default, int size) { int i; names = malloc(sizeof(char *) * size); int needed_size = strlen(default) + 1; for (i = 0; i < size; i++ ) { names[i] = malloc(sizeof(needed_size)); strncpy(names[i], default, needed_size); Select One: Works Great Never Works Works but has Restrictions Part (b) [2 marks] void set_to_default(char **names, char *default, int size) { int i; names = malloc(sizeof(char *) * size); int needed_size = strlen(default) + 1; char * default_name = malloc(sizeof(needed_size)); strncpy(default_name, default, needed_size); for (i = 0; i < size; i++ ) { names[i] = default_name; Select One: Works Great Never Works Works but has Restrictions Page 8 of 22

APRIL 2012 Final Examination CSC 209H1S Part (c) [2 marks] void set_to_default(char **names, char *default, int size) { int i; names = malloc(sizeof(char *) * size); int needed_size = strlen(default) + 1; char default_name[needed_size]; strncpy(default_name, default, needed_size); for (i = 0; i < size; i++ ) { names[i] = default_name; Select One: Works Great Never Works Works but has Restrictions Part (d) [2 marks] void set_to_default(char **names, char *default, int size) { int i; names = malloc(sizeof(char *) * size); for (i = 0; i < size; i++ ) { names[i] = default; Select One: Works Great Never Works Works but has Restrictions Page 9 of 22

CSC 209H1S Final Examination APRIL 2012 Question 5. Part (a) [7 marks] [17 marks] You have a set of input files that are encrypted with a form of run-length encoding and have the following format. The first 4 bytes of the file are an integer in binary representation that indicate the number of header bytes that come next. After the header, the file alternates between one integer followed by one character. You will write a function that given a filename, decrypts that file and sends the decrypted result to a file descriptor. To do this you only care about the pairs of integers and their corresponding characters so first you can skip the header. The integer indicates how many of that character should come next in the file. So, for example, if the data consists of a binary representation of 1 followed by a b and then a binary 5 followed by an o, the output sent to the file-descriptor should be booooo. The last thing the function should do is close the file descriptor. Complete the function decode. int decode(char * filename, int fd) { Page 10 of 22

APRIL 2012 Final Examination CSC 209H1S Part (b) [8 marks] Assume that you have a decode function that works according to the specification. It doesn t matter for this question if you didn t quite manage to get it correct in Part a, we will assume it works. Assume also that you have a corresponding encode function with the signature encode(char * filename, int fd) that reads a series of characters from file descriptor fd, does the run-length encoding and creates and writes the encrypted file to filename. For this question, you must complete the C program below that creates two child processes and communicates with them using pipes. One of the children will call the decode to read an encrypted input file and pass the unencrypted contents to the parent through the pipe. Although it is a bit unrealistic, the parent process you write won t do anything with the unencrypted data except pass it along (through a different pipe) to the other child. The other child will call the encode function to read the raw data from the parent, encrypt it and write it to a new file. You could imagine that in a real program, the parent would be doing something interesting with the unencrypted data before sending it back to be re-enrypted but that would be too much for this question! For full marks, pipes and files must be closed at the appropriate times. Although comments are not required for full marks, they are probably helpful to keep yourself on track and to allow the markers to see what you are trying to do. You do not need to show the error checking on your system calls. int main() { char * original = "original_encrypted_file.xxx"; char * created = "resulting_encrypted_file.xxx"; Page 11 of 22

CSC 209H1S Final Examination APRIL 2012 More space for your answer Page 12 of 22

APRIL 2012 Final Examination CSC 209H1S Part (c) [2 marks] In this course, we have emphasized the importance of error checking, but because of space and time constraints, we have told you not to do any error checking in your answers. For this question choose one of the system calls that you used in part (b) and write a snippet of C code that would replace the code fragment containing the call with code that properly tests for an error. Code from Part B without any error checking: Replacement code that checks for error: Page 13 of 22

CSC 209H1S Final Examination APRIL 2012 Question 6. [8 marks] Study the following program that installs a signal handler. int turn = 0; void handler(int code) { if(turn == 0) { fprintf(stderr, "First\n"); turn = 1; /* D */ else { fprintf(stderr, "Second\n"); kill(getpid(), SIGQUIT); fprintf(stderr,"here\n"); int main() { struct sigaction sa; sa.sa_handler = handler; sigemptyset(&sa.sa_mask); sigaddset(&sa.sa_mask, SIGQUIT); /* A*/ sigaction(sigterm, &sa, NULL); /* B */ fprintf(stderr, "Done\n"); /* C */ return 0; Page 14 of 22

APRIL 2012 Final Examination CSC 209H1S Question 6. (continued) Show the output of the program when events described in each row occur. Treat each row as if the program were restarted. Each event is described as a signal that arrives just before the process executes the line of code following the specified comment line. Give the total output of the program in each case. Default behaviour: SIGQUIT - prints Quit before terminating the process. SIGTERM - prints Terminated before terminating the process. Events Output Two SIGTERM signals arrive one after the other at A SIGTERM arrives at B and SIGTERM arrives at C SIGTERM arrives at B and SIGQUIT arrives at D SIGTERM arrives at B and SIGTERM arrives at D Page 15 of 22

CSC 209H1S Final Examination APRIL 2012 Question 7. [5 marks] Part (a) How do you tell when there is nothing more to read on a pipe or a socket? Part (b) [3 marks] Explain what each of the following system calls do to set up a socket for a server: int bind(int sock, struct sockaddr *addr, int addrlen) int listen(int sock, int n) int accept(int sock, struct sockaddr *addr, int *addrlen) Part (c) Which (if any) of the system calls in the previous question might block? Page 16 of 22

APRIL 2012 Final Examination CSC 209H1S Question 8. [11 marks] Recall from assignment 4, the dropbox client performed a synchronization operation every N seconds that compared last modified times of files on the client to the last modified times of the same files stored on the server. If a file on the server was newer, it was downloaded to the client. If a file on the client was newer, it was uploaded to the server. For this question, we will be implementing a simpler client. Instead of uploading and downloading files, the client will print to standard output the names of the files that are newer on the server. This means that the only messages being sent to and received from the server are sync messages. The other modification we will make to the client is that instead of synchronizing with the server every N seconds, it synchronizes only when the user prompts it to by entering a command on the keyboard. In other words, the client will read from standard input. If it receives the character s it will initiate a synchronization operation as long as no synchronization operation is in progress. If the client is in the middle of a synchronization operation when the user types s, the client will display a message to the user: Sync in progress, try again later and will not initiate a synchronization operation. If the user types q, the client will close the socket and terminate. Complete the code below that uses select to implement this modification. Assume that all variables and constants have been correctly initialized and the socket connection to the server has already been established. Assume the user will only type valid input. No error handling is required. Part (a) Explain the purpose of using select in the case. Here are the types, variables and constants needed for the code below. Note the function prototype for getnextfile. You do not need to implement it, but are welcome to use it. // data structure for sending and receiving file information // from the server struct sync_message { char filename[maxname]; time_t mtime; int size; ; // constants used to keep track of the current state of input #define IDLE 0 // No synchronization operation in progress. #define SYNC 1 // Synchronization in progress. int sock; DIR *dir; // the file descriptor that connects to the server // the directory pointer // Gets the next file entry from the directory, and fills in // correct values in r. Assume this is implemented. int getnextfile(dir *dir, struct sync_message *r); Page 17 of 22

CSC 209H1S Final Examination APRIL 2012 Part (b) [2 marks] Finish setting up the variables needed to run select correctly as the code continues in the next subquestion. fd_set rset, allset; Part (c) [8 marks] Complete the loop below to handle input coming from the user. struct sync_message request, response; state = IDLE; while(1) { rset = allset; select(maxfd + 1, &rset, NULL, NULL, NULL); if(fd_isset(sock, &rset)) { if(state == SYNC) { read(sock, &response, sizeof(struct sync_message)); if(response.mtime > request.mtime) { // server has newer version printf("%s %d", response.filename, response.mtime); if(getnextfile(dir, &request) == 0) { state = IDLE; else { write(sock, request, sizeof(struct sync_message)); else { fprintf(stderr, "error state"); Page 18 of 22

APRIL 2012 Final Examination CSC 209H1S Question 8. (continued) Page 19 of 22

CSC 209H1S Final Examination APRIL 2012 This page can be used if you need additional space for your answers. Total Marks = 77 Page 20 of 22

APRIL 2012 Final Examination CSC 209H1S C function prototypes and structs: int accept(int sock, struct sockaddr *addr, int *addrlen) int bind(int sock, struct sockaddr *addr, int addrlen) int close(int fd) int closedir(dir *dir) int connect(int sock, struct sockaddr *addr, int addrlen) int dup2(int oldfd, int newfd) int execlp(const char *file, char *argv0,..., (char *)0) int execvp(const char *file, char *argv[]) int fclose(file *stream) int FD ISSET(int fd, fd set *fds) void FD SET(int fd, fd set *fds) void FD CLR(int fd, fd set *fds) void FD ZERO(fd set *fds) char *fgets(char *s, int n, FILE *stream) int fileno(file *stream) pid t fork(void) FILE *fopen(const char *file, const char *mode) size t fread(void *ptr, size t size, size t nmemb, FILE *stream); size t fwrite(const void *ptr, size t size, size t nmemb, FILE *stream); int gettimeofday(struct timeval *tv, struct timezone *tz); // tz is often NULL struct hostent *gethostbyname(const char *name) unsigned long int htonl(unsigned long int hostlong) /* 4 bytes */ unsigned short int htons(unsigned short int hostshort) /* 2 bytes */ char *index(const char *s, int c) int kill(int pid, int signo) int listen(int sock, int n) unsigned long int ntohl(unsigned long int netlong) unsigned short int ntohs(unsigned short int netshort) int open(const char *path, int oflag) /* oflag is O_WRONLY O_CREAT for write and O_RDONLY for read */ DIR *opendir(const char *name) int pclose(file *stream) int pipe(int filedes[2]) FILE *popen(char *cmdstr, char *mode) ssize t read(int d, void *buf, size t nbytes); struct dirent *readdir(dir *dir) int select(int maxfdp1, fd set *readfds, fd set *writefds, fd set *exceptfds, struct timeval *timeout) int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) /* actions include SIG_DFL and SIG_IGN */ int sigaddset(sigset t *set, int signum) int sigemptyset(sigset t *set) int sigprocmask(int how, const sigset t *set, sigset t *oldset) /*how has the value SIG BLOCK, SIG UNBLOCK, or SIG SETMASK */ unsigned int sleep(unsigned int seconds) int socket(int family, int type, int protocol) /* family=pf INET, type=sock STREAM, protocol=0 */ int sprintf(char *s, const char *format,...) int stat(const char *file name, struct stat *buf) char *strchr(const char *s, int c) size t strlen(const char *s) char *strncat(char *dest, const char *src, size t n) int strncmp(const char *s1, const char *s2, size t n) char *strncpy(char *dest, const char *src, size t n) char *strrchr(const char *s, int c) int wait(int *status) int waitpid(int pid, int *stat, int options) /* options = 0 or WNOHANG*/ ssize t write(int d, const void *buf, size t nbytes); Page 21 of 22

CSC 209H1S Final Examination APRIL 2012 WIFEXITED(status) WIFSIGNALED(status) WIFSTOPPED(status) WEXITSTATUS(status) WTERMSIG(status) WSTOPSIG(status) Useful structs struct sigaction { void (*sa handler)(int); sigset t sa mask; int sa flags; struct dirent { int d namelen; int d name[maxnamelen]; struct hostent { char *h name; /* official name of host */ char **h aliases; /* alias list */ int h addrtype; /* host address type */ int h length; /* length of address */ char *h addr; /* address */ struct sockaddr in { sa family t sin family; unsigned short int sin port; struct in addr sin addr; unsigned char pad[8]; /*Unused*/ Shell comparison operators Shell Description -d filename Exists as a directory -f filename Exists as a regular file. -r filename Exists as a readable file -w filename Exists as a writable file. -x filename Exists as an executable file. -z string True if empty string str1 = str2 True if str1 equals str2 str1!= str2 True if str1 not equal to str2 int1 -eq int2 True if int1 equals int2 -ne, -gt, -lt, -le For numbers!=, >, >=, <, <= For strings -a, -o And, or. Useful shell commands: cat, cut, echo, ls, read, sort, uniq, wc expr match STRING REGEXP expr ARG1 + ARG2 set (Note: with no arguments set prints the list of environment variables) ps aux - prints the list of currently running processes grep (returns 0 if match is found, 1 if no match was found, and 2 if there was an error) grep -v displays lines that do not match diff (returns 0 if the files are the same, and 1 if the files differ) Page 22 of 22 End of Examination