User Tools

Site Tools


Action disabled: revisions
os:lab07
Return to Home page

Return to Operationg Systems home


Operating Systems Course: Lab07

Laboratory number 07

Exercise 01: Bash script

Realize a bash script that receives three parameters from the command line:

  1. the name of a directory
  2. the name of a function
  3. the name of an output file.

The script must:

  • search all the occurrences of function, inside all the files of the sub-tree of the specified directory
  • for each occurrence, store in the output file, the name of the file, the number of the line, and the line in which the function appears
  • in the output file, lines must be ordered taking into account the name of the file (primary key) and the line number (secondary key).

Write two versions of the script:

  • version 1: without the use of the statement for-in
  • version 2: with the use of the statement for-in

Exercise 02: Bash script

Realize a bash script that:

  • takes in input (from command line or from standard input) the name of a file
  • prints (in the screen) the number of characters of the longest line and the number of lines of the file.

Suppose that rows of the file do not contain spaces.

Exercise 03: Bash script

Realize a bash script that:

  • takes in input (from command line or from standard input) the name of a directory
  • renames all the files and all the directories contained in the directory, so that the new names are identical to the original ones but consist of only lowercase letters.

Exercise 04: Bash script

A textual file (ASCII) has a not definite format, i.e., it includes an indefinite number of rows, each of which contains an indefinite number of strings.

Realize a bash script that prints on standard output the absolute frequency of all the strings contained in the files.

Example:
With the following input file:

input.txt
the imagination of nature is far
far greater than the imagination
of man

(by Richard P. Feynman)

the script must print (in a not defined order):

the 2
imagination 2
of 2
nature 1
is 1
far 2
greater 1
than 1
man 1

Suppose that the name of the input file is passed from the command line, but in the case it is not present, the name of the file must be read from standard input.

Suggestions:

  • use two vectors, one to store words, and one to store the absolute frequency of the corresponding words
  • read the content of the file with the construct for-in + cat

Exercise 05: Bash script

A bash script receives two parameters from the command line:

  1. the name of a process
  2. a time interval.

The bash script must check, at each time interval, if the process is present in the system. If the process remains in the Z state (i.e., zombie) for more than 5 consecutive checks, the script must terminate.

Suggestion:
The command ps -el provide an output similar to the following:

UID  PID PPID F    CPU PRI NI RSS  S  ADDR    TTY TIME    CMD
  0   1  0    4000 0   31  0   568 Ss 6fd9cd4 ??  0:00.20 /sbin/launchd
  0  10  1    4000 0   31  0  1292 R+ 6fd9384 ??  0:00.59 /usr/libexec/kextd
  0  11  1    4000 0   31  0  3412 Z  6fd982c ??  0:02.10 /bin/ls

This output, properly parsed, can provide the needed informations to solve the problem.

Note that the character Z in the column labeled with S indicates the process is a zombie.


If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it

You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/os/lab07?do=revisions
/web/htdocs/www.skenz.it/home/data/pages/os/lab07.txt · Last modified: 2024/04/08 22:35 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki
Privacy Policy