User Tools

Site Tools


os:lab08
Return to Home page

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
os:lab08 [2019/12/04 15:32]
zioskenz
os:lab08 [2019/12/05 07:56] (current)
zioskenz
Line 6: Line 6:
  
 ==== Exercise 01: Bash script ==== ==== Exercise 01: Bash script ====
-Realize a bash script that receives three parameters from command line:+Realize a bash script that receives three parameters from the command line:
   - the name of a //​directory//​   - the name of a //​directory//​
   - the name of a //​function//​   - the name of a //​function//​
Line 12: Line 12:
  
 The script must: The script must:
-  * search inside all the files of the sub-tree of the specified //directory//, all the occurrence of the //function//+  * 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   * 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).   * in the //output file//, lines must be ordered taking into account the name of the file (primary key) and the line number (secondary key).
Line 24: Line 24:
 Realize a bash script that: Realize a bash script that:
   * takes in input (from command line or from standard input) the name of a file   * takes in input (from command line or from standard input) the name of a file
-  * print (in the screen) the number of characters of the longest line and the number of lines of the 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.zi.+Suppose that rows of the file do not contain spaces.
  
  
Line 34: Line 34:
  
  
 +==== 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.
  
-Esercizio 04 +**Example:​**\\ 
-Script bash +With the following input file: 
-------------+<file txt input.txt>​ 
 +the imagination of nature is far 
 +far greater than the imagination 
 +of man 
 +</​file>​ 
 +(by Richard P. Feynman)
  
-Un file di testo (ASCIIha formato indefinito, ovvero include +the script must print (in a not defined order): 
-un numero indefinito di righe ciascuna delle quali comprende +<​code>​ 
-un numero indefinito di stringhe.+the 2 
 +imagination 2 
 +of 2 
 +nature 1 
 +is 1 
 +far 2 
 +greater 1 
 +than 1 
 +man 1 
 +</​code>​
  
-Si scriva uno script bash in grado di visualizzare su standard +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.
-output la frequenza assoluta di tutte le stringhe presenti nel +
-file.+
  
-Esempio +**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''​
  
-Sia il file di ingresso il seguente: 
  
 +==== Exercise 05: Bash script ====
 +A bash script receives two parameters from the command line:
 +  - the name of a //process//
 +  - a //time interval//.
  
-mi illumino di immenso +The bash script must checkat each //time interval//, if the //process// is present ​in the system.  
-illumino di immenso +If the //process// remains ​in the ''​Z''​ state (i.e., zombie) for more than consecutive checksthe script ​must terminate.
-di immenso +
-immenso +
- +
-Occorre visualizzare (in qualunque ordine) +
- +
-immenso 4 +
-di 3 +
-illumino 2 +
-mi 1 +
- +
-Si supponga che il nome del file di ingresso sia indicato sulla +
-riga di comandoma nel caso e in cui non sia presente sulla riga +
-di comando, venga letto da tastiera+
- +
-Suggerimenti +
------------- +
- +
-- si utilizzino due vettori, uno per la memorizzazione delle parole +
-  e uno per la memorizzazione delle relative frequenza assolute. +
-- si leggano le stringhe del file con il costrutto "for-in + cat". +
- +
- +
- +
-Esercizio 05 +
-Script bash +
------------- +
- +
-Uno script bash riceve due parametri:​ +
-* il nome di un processo +
-* un intervallo di tempo. +
-Esso deve verificare a intervalli di tempo pari a quello +
-specificato se il processo indicato ​e' ancora presente nel +
-sistema. +
-Se il processo rimane nello stato Z per piu' di verifiche +
-successivelo script ​lo deve terminare. +
- +
-Suggerimento +
------------- +
- +
-Il comando +
-ps -el +
-fornisce un output simile al seguente+
  
 +**Suggestion:​**\\
 +The command ''​ps -el''​ provide an output similar to the following:
 +<code bash>
 UID  PID PPID F    CPU PRI NI RSS  S  ADDR    TTY TIME    CMD 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   ​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  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   0  11  1    4000 0   ​31 ​ 0  3412 Z  6fd982c ??  0:02.10 /bin/ls
 +</​code>​
 +This output, properly parsed, can provide the needed informations to solve the problem.
  
-Opportunamente parsificato esso fornisce le informazioni necessarie +Note that the character ''​Z'​' in the column labeled with ''​S'' indicates the process is a zombie.
-per risolvere il problema indicato. +
-Si noti che il carattere ​'​Z' ​nella colonna denominata ​indica che il +
-processo e' ​uno 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/lab08?rev=1575469922&do=diff
/web/htdocs/www.skenz.it/home/data/attic/os/lab08.1575469922.txt.gz · Last modified: 2019/12/04 15:32 by zioskenz

Privacy Policy