Lab Exercise 1

Due: April 18, 2022
Points: 100


Please form a team of 2 or 3. Include the names of all team members in the header comment. One person needs to submit the program; the other team members must submit a short note identifying who turned in the program.

  1. (50 points) Write a program that terminates a second program after a given period of time. Your program is to have the following interface:

    timeout s command . . .

    When this command is issued, the timeout program is to execute “command …”. After s seconds have passed, timeout is to send a SIGTERM signal to the command timeout is running.

    You must use fork(2) and execve(2) to run the subcommand.

    Don’t forget to check for possible errors, such as a negative number of seconds or no command!

  2. (25 points) Write a program to print the numeric and symbolic names of any signals it receives, and the date and time it is received. For example, if I send the process a signal 1, it must print:

    Fri Sep 19 23:34:19 2022 Received signal 1 (SIGHUP)

    The program should loop until sent signal 9 (SIGKILL). This signal cannot be caught.

  3. (25 points) Write a program that takes the names of two files as arguments. It determines whether these files are links to each other.

    If the files are hard links, print

    These files are linked.

    If file1 is a symbolic link to file2, print

    file1 is a symbolic link to file2.

    If the files are not linked, print

    The files are not linked.

    If a system error occurs (for example, a file does not exist), use perror(3) to print the appropriate error message.


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 150, Operating Systems
Version of April 5, 2022 at 5:39PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh