CS810D Advanced Programming in the UNIX Environment Fall 2008 Quiz 4 FULL NAME ______________________________________ USERNAME ______________________________________ 1) Which of the following is the main feature of non-blocking I/O? (2 points) a) typical input/output calls return EWOULDBLOCK if they cannot complete immediately b) the process receives SIGIO if a typical input/output call cannot complete immediately c) the kernel sends EINPROGRESS to all other processes currently performing typical input/output Correct answer: (a) 2) Give an example of a system call that may block and indicate under what circumstances it will block. (2 points) Possible correct answer: read(2) from a pipe/fifo/socket when no data is available (yet). 3) Name three things that a daemon process should do. (3 points) Some correct answers: - fork off parent - change umask - become session leader - change cwd - close or redirect file desriptors - open logs 4) Name two sources from which a syslog daemon may collect messages. (2 points) - kernel messages via /dev/klog - library calls to syslog(3) - UDP socket (port 514) 5) Give two examples each (ie four in total) of a syslog facility and a syslog level. (4 points) Facilities: LOG_AUTH, LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN, LOG_LPR, LOG_MAIL, LOG_NEWS, LOG_SYSLOG, LOG_USER, LOG_UUCP, LOG_LOCAL[0-7] Level: LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG 6) Name the four steps completed (by separate tools, actually) in the compilation process. (4 points) Preprocessing (cpp), Compilation (cc), Assembly (as), Linking (ld). 7) Consider the following Makefile: (3 points) PROG= cp OBJS= cp.o utils.o CFLAGS= -Wall -g CC= cc all: ${PROG} ${PROG}: ${OBJS} ${CC} ${LDFLAGS} ${OBJS} -o ${PROG} cp.o: extern.h utils.o:extern.h Write down the exact commands executed after invoking running $ CC=gcc make Solution: cc -Wall -g -c cp.c cc -Wall -g -c utils.c cc cp.o utils.o -o cp The definition in the Makefile overwrites the definition in the environment. Note the difference if you had run: $ make CC=gcc gcc -Wall -g -c cp.c gcc -Wall -g -c utils.c gcc cp.o utils.o -o cp Here the definition on the command-line *after* the 'make' command overwrites the definition in the Makefile.