Table of Contents

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:

Write two versions of the script:

Exercise 02: Bash script

Realize a bash script that:

Suppose that rows of the file do not contain spaces.

Exercise 03: Bash script

Realize a bash script that:

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:

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.