Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi I don\'t want you to do my assignment, but I would appreciate if you could ex

ID: 3537067 • Letter: H

Question

Hi I don't want you to do my assignment, but I would appreciate if you could explain me in a simpler way the theory i need to know to start this assignment, thank you!


Task description


FIFOs, or named pipes are features of UNIX systems which allow locations on the filesystem to be

associated with pipes that would usually be shared between a parent and a child process. You can

open and read FIFOs like normal files, with one important difference: any read operation on these

will block until there is new data to be read, or another process has closed the FIFO. This means that

you need to think about how and when to read from these named pipes in order to stop your program

from becoming unresponsive. Any files which are FIFOs will be explicitly stated in this document.

Although FIFOs will be used during correctness testing, you are able to use regular files for your own

testing. From the point of view of your program, a regular file will be like a FIFO that never blocks.

1


Stage one%u2014 Catching signals and identifying devices

For this stage, your program devm needs to catch signals issued by our testing program, which will

indicate a new device connection. It then needs to read from a FIFO to identify the device type, and

log all activity along the way.

A dictionary of devices which may be connected will be given, in a file called known_devices.

Each device has a unique identifier (ID) associated with it, which you can look up in this dictionary to

determine what type of device it is. For this assignment, only two types of devices will be connected:

type mouse or keyboard. The following is an example of the known_devices file:

1 ID 0461:4d22 Primax Electronics, Ltd

2 ID 056a:00dd Wacom Co., Ltd Tablet

3 ID 045e:00dd Microsoft Corp. Comfort Curve Keyboard 2000 V1.0

4 ID 046d:c016 Logitech, Inc. Optical Wheel Mouse

5 ID 1d6b:0002 Linux Foundation 2.0 root hub

6 ID 413c:2003 Dell Computer Corp. Keyboard

7 ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

8 ID 05fe:0011 Chic Technology Corp. Browser Mouse

The ID takes the form 0123:abcd where any digit may be a hexadecimal number. Any hexadecimal

digit will be a base-10 digit [0-9], or a lowercase character [a-f]. You must search each line to

find out what type of device the ID corresponds to; you should be looking for the string %u201Cmouse%u201D or

%u201Ckeyboard%u201D, which will appear somewhere in the line, or not at all. Also note from the above example

that you should be searching case-insensitively. If neither string %u201Cmouse%u201D or %u201Ckeyboard%u201D appear in the

line, you may discard that line (for the purposes of this assignment).

When your program devm starts, it should immediately start logging its activities to a file called

devm.log. This file should be opened in append mode, such that previous data will not be erased

and for the henceforth this document will be referred to as %u201Cthe log file%u201D or %u201Cthe log%u201D.

Each line of the log file should look like this (using a UNIX timestamp1:

1 [<timestamp>] <message>

When devm first starts up, it should write the following message to the log file: devm started. In

the log file itself, that line would look like:

1 [1368869693] devm started

Upon startup, your program should also write its PID (process ID) to a file called devm.pid. Upon

termination of your program, you should remove this file. Your program should then read in the

previously mentioned known_devices file, and then go into a waiting state. From this waiting state

it should catch the signals SIGUSR1 and SIGTERM.

Your program devm should catch the UNIX signal SIGUSR1, which will communicate to the program

that a new device has been connected. Upon receiving this signal, devm should read a single

line from the FIFO new_devices, which will contain exactly one ID corresponding to a device, as

above. An example line from new_devices is:

1 045e:00dd

1Number of seconds since 1 January 1970. See http://en.wikipedia.org/wiki/Unix_time

Operating System and Machine Principals Page 2 of 8

COMP2129

This signal indicates that the device with the ID just read has been connected. You should log this activity

in a message Device connected: <device type> <device id> at <device path>,

where device type will be either keyboard or mouse corresponding to the ID read from known_devices,

device id will be the ID read in from new_devices, and device path will be dev/USBx, where

x corresponds to the connection order of the devices. The first device will be connected with pathname

dev/USB0, the next with dev/USB1, and so forth. An example line from the log upon the

connection of device ID 045e:00dd would be:

1 [1368869693] Device connected: keyboard 045e:00dd at dev/USB0

Your program should also catch SIGTERM, which will indicate that devm should terminate. Upon

catching this signal, you should write the message SIGTERM caught, devm closing to the logfile,

and then your program should terminate. An example log line for this is:

1 [1368869693] SIGTERM caught, devm closing

For the first stage of the assignment, your program will be marked on the following:

%u2022 Writing the correct lines to the log file for open and close of devm.

%u2022 Catching SIGUSR1 and logging the correct device connection to the log file.

%u2022 Terminating on SIGTERM.

%u2022 Having a correct timestamp for each line of the log (with a tolerance of 5 seconds).

%u2022 Writing the correct PID, and removing the pidfile on exit.

The following is a state diagram of devm for this stage of the assignment.

It is intended to be a guide only %u2014 please refer to the descriptions above for exact behaviour.

Explanation / Answer

1. Take a look at: http://www.cs.fredonia.edu/zubairi/s2k2/csit431/more_pipes.html (Creating a named file: This will be your log file).


2. The various signals are given here: http://ods.com.ua/win/eng/program/Perl5Unleashed/ch14.phtml


3. The same link provides how to write a program for sending signal using perl.

Using shell it will be even more easier to handle signal calls.

Check this program in the above link: Listing 14.2. Signal handler usage.

It shows how to captue signals.

Now use the above link to send it to a FIFO file.

SIGIO 29 Asynchronous I/O