Spring 2004 CSE4001 Exam #1. Open book, open notes. Name _________________ 1. For the following, cmd1 and cmd2 are arbitrary UNIX commands, and file1 and file2 are files owned by you. Write UNIX (csh) commands to: (4 pts each). ANSWERS a. Run cmd1 and append its output to file1. cmd1 >> file1 b. Run cmd1, and if it returns a $status of 0, run cmd2. cmd1 && cmd2 c. Redirect the standard output and standard error of cmd1 |& cmd2 cmd1 to the standard input of cmd2. d. Replace file1 with the output of cmd1. cmd1 > file1 e. Set the environment variable $FOO to the output of cmd1. setenv FOO `cmd1` f. Run cmd1 passing the names of all files in the current cmd1 * directory as arguments. g. Run cmd1 in the background at low priority. nice cmd1 & h. Sort file1 and store the result in file2. sort file1 > file2 i. Compare file1 and file2 (as text files). diff file1 file2 (cmp is for binary files) j. Print all lines in file1 containing "foo". grep foo file1 (or fgrep, egrep) k. Show the owners and permissions for file1 and file2. ls -l file* l. Show what background processes are currently running. ps (or jobs) m. Kill the process with process ID 12345. kill 12345 n. Create a directory named dir1. mkdir dir1 o. Set permissions on dir1 so that anyone may list the chmod 755 dir1 files int it, or read or execute those files, but only you can add or remove files. p. Set permissions on file1 and file2 so that anyone can chmod 644 file* read them but only you can edit them. q. Set permissions so that anyone may execute file1. chmod a+x file1 r. If user A executes a program file owned by B, who A owns the process? s. If user A executes a program file owned by B that is "setuid C", then what user's priveliges does the process C have? t. Which user(s) of A, B, and C can kill this process? A 2. Write a C program to print "hello world" and a main() { linefeed to standard output using the write() system write(1,"hello world\n",12); call (20 pts). }