Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 1

Perl

you will write a Perl program that reads from a file similar to the output of
Unix’ command top (a file that contains information about the tasks running on the system).
Your program will process options and print the requested output to the standard output.
These are the specifications for your Perl program:
1. The file containing your program must be named displaytasks.pl
2. It must be invoked as:
displaytasks.pl option task_file
The program must check that the task_file argument is an existing and readable file. If
not, it must print a message of your choice to the standard output and exit. The format for
file task_file and the values for the option argument are described below.
3. File task_file can have any arbitrary name. It must be a file of text with the following
format:
a. The file consists of an arbitrary, yet reasonable, number of lines (including,
possibly, zero lines). Each line corresponds to a task.
b. Each line must contain four fields separated by spaces.
c. The four fields are: process ID, memory size, CPU time and program name.
d. Field process ID is an integer between 0 and 32768. Fields memory size and CPU
time are integers between 0 and 99999999. Field program name is a string
between 1 and 20 characters in length containing no spaces.
The following example should be regarded as the reference specification for the format of
file task_file:
1 4730 1031782 init
4 0 6 events
2190 450 0 top
21413 5928 1 sshd
22355 1970 2009 find

Important note: your program does not need to verify that file task_file complies with the
specifications. You can simply assume that the file meets all the specifications given above.
(1) Your program can be invoked with option: -a. In this case, it must print all the lines of file
task_file sorted alphabetically by field program name (if two or more lines have the same
value of field program name, they can be printed in any arbitrary order; in all cases, we will
not test this case).
Example with the example task_file given above:

Command line: displaytasks.pl -a task_file

Output:

4 0 6 events

22355 1970 2009 find

1 4730 1031782 init

21413 5928 1 sshd

2190 450 0 top

In the case in which file task_file is empty, your program will print:

No tasks found

 

(2)Your program can be invoked with option: -m. In this case, it must print the following string:

The total memory size: <total memory size for all tasks in task_file>KB

The total momory size is computed by simply adding up the values of field memory size for all lines. Example with the example task_file given above:

Command line: displaytasks.pl -m task_file

Output:

Total memory size: 13078 KB

In the case in which file task_file is empty, your program will print:

No memory used

 

(3)Your program can be invoked with option: -t. In this case, it must print the following string:

Total CPU time: <totaol CPU time for all tasks in task_file>seconds

The total CPU time is computed by simply adding up the values of field CPU time for all lines.

Example with the example task_file given above:

Command line:

displaytasks.pl -t task_file

Output:
Total CPU time: 1033798 seconds
In the case in which file task_file is empty, your program will print:
No CPU time used

 

(4)Your program can be invoked with option: -s memory threshold. In this case, it must print
all the lines of file task_file where the value of field memory size is greater than or equal to
the value of memory threshold, in appearance order. The format of argument memory
threshold is the same as that of field memory size.
Example with the example task_file given above:
Command line:
displaytasks.pl -s 2000 task_file

Output:
1 4730 1031782 init
21413 5928 1 sshd
In the case in which no values of field memory size meet the requirement (including the
case of an empty file), your program must print:
No tasks with the specified memory size

 

(5)Your program can be invoked with option: -n. In this case, it must only print your name,
surname, student ID and date of completion of your assignment, in a format of your choice.
Please note that argument task_file is still required.

 

(6)If your program is invoked with any other syntax than those specified above, it must print a
message of your choice to the standard output and exit.
Examples of incorrect syntax:
displaytasks.pl -Z task_file
displaytasks.pl -u