<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Coci</id>
	<title>Sistemi Operativi - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Coci"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/Coci"/>
	<updated>2026-04-30T21:33:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=754</id>
		<title>ProvaPratica 2013.06.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2013.06.21&amp;diff=754"/>
		<updated>2014-05-26T10:53:34Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Esercizio 1 ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
/* Comparison function for iNode&lt;br /&gt;
 * Input:    2 dirent pointers&lt;br /&gt;
 * Output:&lt;br /&gt;
 *           1,   if iNode[a] &amp;gt; iNode[b]&lt;br /&gt;
 * 	     0,   if iNode[a] == iNode[b]&lt;br /&gt;
 * 	    -1,   else */&lt;br /&gt;
int iNodeComparison(const struct dirent **a, const struct dirent **b)&lt;br /&gt;
{&lt;br /&gt;
    long iNodeA = (long)(*a)-&amp;gt;d_ino;&lt;br /&gt;
    long iNodeB = (long)(*b)-&amp;gt;d_ino;&lt;br /&gt;
    return (iNodeA &amp;gt; iNodeB) - (iNodeA &amp;lt; iNodeB);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Scan a directory -&amp;gt;&lt;br /&gt;
 * Order the entries by iNode number -&amp;gt;&lt;br /&gt;
 * Print name and iNode of each file. */&lt;br /&gt;
void scanDirectory(char *dir)&lt;br /&gt;
{&lt;br /&gt;
    int result, iterator;&lt;br /&gt;
    struct dirent **files;&lt;br /&gt;
&lt;br /&gt;
    result = scandir(dir, &amp;amp;files, NULL, iNodeComparison);&lt;br /&gt;
&lt;br /&gt;
    // Check if any errors occurred&lt;br /&gt;
    if (result &amp;lt; 0)&lt;br /&gt;
    {&lt;br /&gt;
        perror(&amp;quot;scandir()&amp;quot;);&lt;br /&gt;
	exit(EXIT_FAILURE);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Loop through directory entries&lt;br /&gt;
    for(iterator = 0; iterator &amp;lt; result; iterator++)&lt;br /&gt;
    {&lt;br /&gt;
	printf(&amp;quot;%s/%s %li\n&amp;quot;, dir, files[iterator]-&amp;gt;d_name, (long)files[iterator]-&amp;gt;d_ino);&lt;br /&gt;
&lt;br /&gt;
	// Garbage collection&lt;br /&gt;
	free(files[iterator]);&lt;br /&gt;
    }&lt;br /&gt;
    free(files);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Entry point&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    char cwd[1024];&lt;br /&gt;
&lt;br /&gt;
    // if (number of parameters&lt;br /&gt;
    switch(argc)&lt;br /&gt;
    {&lt;br /&gt;
    	// == 0) =&amp;gt; Use the current directory&lt;br /&gt;
    	case 1:&lt;br /&gt;
    	    if (!getcwd(cwd, sizeof(cwd)))&lt;br /&gt;
    	    {&lt;br /&gt;
    		perror(&amp;quot;getcwd()&amp;quot;);&lt;br /&gt;
    		exit(EXIT_FAILURE);&lt;br /&gt;
    	    }&lt;br /&gt;
    	    scanDirectory(cwd);&lt;br /&gt;
    	    exit(EXIT_SUCCESS);&lt;br /&gt;
&lt;br /&gt;
    	// == 1) =&amp;gt; Use the given directory&lt;br /&gt;
    	case 2:&lt;br /&gt;
    	    scanDirectory(argv[1]);&lt;br /&gt;
    	    exit(EXIT_SUCCESS);&lt;br /&gt;
&lt;br /&gt;
    	// &amp;gt; 1) =&amp;gt; Wrong input&lt;br /&gt;
    	default:&lt;br /&gt;
    	    printf(&amp;quot;The function requires 0 or 1 parameters.\n&amp;quot;);&lt;br /&gt;
    	    exit(EXIT_FAILURE);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
La mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*Scrivere un programma che stampi il numero di inode di ogni file presente in una direcotory passata come argomento (o della&lt;br /&gt;
direcotry corrente se il programma viene chiamato senza parametri) e stampi l'elenco in ordine crescente di numero di i-node.&lt;br /&gt;
Es:&lt;br /&gt;
$ lsino demo&lt;br /&gt;
demo/. 1972484&lt;br /&gt;
demo/.. 1971834&lt;br /&gt;
demo/1.c 1972528&lt;br /&gt;
demo/a.out 1972485&lt;br /&gt;
demo/l1 1972486&lt;br /&gt;
demo/l2 1972486&lt;br /&gt;
demo/l3 1972486&lt;br /&gt;
demo/link.c 1972528*/&lt;br /&gt;
&lt;br /&gt;
#define _SVID_SOURCE&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]){&lt;br /&gt;
	struct stat sb;&lt;br /&gt;
	char cwd[1024];&lt;br /&gt;
	struct dirent **namelist;&lt;br /&gt;
	int n; /*valore di ritorno di scandir*/&lt;br /&gt;
	int i=0;&lt;br /&gt;
		&lt;br /&gt;
	if(argc&amp;gt;1){ /*se la directory e' stata data in input*/&lt;br /&gt;
		strcpy(cwd,argv[1]);&lt;br /&gt;
		}	&lt;br /&gt;
	else{ /*se la directory non viene data in input*/&lt;br /&gt;
		getcwd(cwd, sizeof(cwd));&lt;br /&gt;
	}&lt;br /&gt;
	/*ora dentro cwd c'è la cartella interessata*/&lt;br /&gt;
	&lt;br /&gt;
	n = scandir(cwd, &amp;amp;namelist, NULL, alphasort);&lt;br /&gt;
	&lt;br /&gt;
	if(n&amp;lt;0)&lt;br /&gt;
		perror(&amp;quot;scandir&amp;quot;);&lt;br /&gt;
	else {&lt;br /&gt;
		while (i&amp;lt;n) {&lt;br /&gt;
			printf(&amp;quot;%s/%s %ld\n&amp;quot;, cwd,namelist[i]-&amp;gt;d_name,(long)namelist[i]-&amp;gt;d_ino);&lt;br /&gt;
			free(namelist[i]);&lt;br /&gt;
			i++;&lt;br /&gt;
	    }&lt;br /&gt;
	free(namelist);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Non mi è chiara una cosa: nel testo specifica &amp;quot;stampi l'elenco in ordine crescente di numero di i-node&amp;quot;, tuttavia nell'esempio sono ordinati grazie a quella che penso sia l'alphasort e quindi è la soluzione che ho sviluppato io.&lt;br /&gt;
Giulia N.&lt;br /&gt;
&lt;br /&gt;
== Esercizio 2 ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang =&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
#define PATH_SIZE 1024&lt;br /&gt;
&lt;br /&gt;
int iNoSort(const struct dirent** dir1, const struct dirent** dir2){&lt;br /&gt;
	int a = (*dir1)-&amp;gt;d_ino;&lt;br /&gt;
	int b = (*dir2)-&amp;gt;d_ino;&lt;br /&gt;
	if (a&amp;lt;b) return -1;&lt;br /&gt;
	else if (a&amp;gt;b) return 1;&lt;br /&gt;
	else return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char** argv){&lt;br /&gt;
	struct dirent** namelist;&lt;br /&gt;
	int n, i, j;&lt;br /&gt;
	int link = 0;&lt;br /&gt;
	char path[PATH_SIZE];&lt;br /&gt;
	if (argc == 1) {strcpy(path, &amp;quot;./&amp;quot;);}&lt;br /&gt;
	else if (argc == 2) {strcpy(path, argv[1]);}&lt;br /&gt;
	n = scandir(path, &amp;amp;namelist, NULL, iNoSort);&lt;br /&gt;
	if (n == -1) {perror(&amp;quot;scandir&amp;quot;); exit(1);}&lt;br /&gt;
	for (i=0; i&amp;lt;n; i++){&lt;br /&gt;
		//printf(&amp;quot;%s%s %d\n&amp;quot;, path, namelist[i]-&amp;gt;d_name, (int) namelist[i]-&amp;gt;d_ino);&lt;br /&gt;
		if (namelist[i]-&amp;gt;d_ino == 0) continue;&lt;br /&gt;
		for(j = i+1; j&amp;lt;n; j++){&lt;br /&gt;
			if (namelist[j]-&amp;gt;d_ino == namelist[i]-&amp;gt;d_ino){&lt;br /&gt;
				if (link == 0) {printf(&amp;quot;%s &amp;quot;, namelist[i]-&amp;gt;d_name); link++;}&lt;br /&gt;
				printf(&amp;quot;%s &amp;quot;,namelist[j]-&amp;gt;d_name);&lt;br /&gt;
				namelist[j]-&amp;gt;d_ino = 0;&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		if(link &amp;gt; 0) printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
		link = 0;&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Alessandro C.&lt;br /&gt;
&lt;br /&gt;
== Esercizio 3 ==&lt;br /&gt;
&lt;br /&gt;
[Python 3]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
'''&lt;br /&gt;
Prova Pratica di Laboratorio di Sistemi Operativi&lt;br /&gt;
20 giugno 2013&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
URL: http://www.cs.unibo.it/~renzo/so/pratiche/2013.06.21.pdf&lt;br /&gt;
&lt;br /&gt;
@author: Tommaso Ognibene&lt;br /&gt;
'''&lt;br /&gt;
&lt;br /&gt;
import os, sys, hashlib&lt;br /&gt;
&lt;br /&gt;
def Main(argv):&lt;br /&gt;
    # Check number of arguments&lt;br /&gt;
    if len(argv) != 1:&lt;br /&gt;
        print(&amp;quot;The function does not require arguments to be passed in.&amp;quot;)&lt;br /&gt;
        return&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
    sameSize = { }&lt;br /&gt;
    PopulateSameSize(sameSize)&lt;br /&gt;
    &lt;br /&gt;
    # Build a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
    sameContent = { }&lt;br /&gt;
    for filePaths in sorted(sameSize.values(), key = len, reverse = True):&lt;br /&gt;
        # No files with same size =&amp;gt; No files with same content&lt;br /&gt;
        if len(filePaths) &amp;lt; 2: break&lt;br /&gt;
        PopulateSameContent(filePaths, sameContent)&lt;br /&gt;
&lt;br /&gt;
    # Print results&lt;br /&gt;
    PrintResults(sameContent)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;Done!&amp;quot;)&lt;br /&gt;
     &lt;br /&gt;
# Populate a dictionary with key-value pair {file size - [file name]}&lt;br /&gt;
def PopulateSameSize(sameSize):&lt;br /&gt;
    for dirPath, _, fileNames in os.walk(os.getcwd()):&lt;br /&gt;
        for fileName in fileNames:&lt;br /&gt;
            filePath = os.path.join(dirPath, fileName)&lt;br /&gt;
            fileSize = os.path.getsize(filePath)&lt;br /&gt;
            sameSize[fileSize] = sameSize.get(fileSize, []) + [filePath]  &lt;br /&gt;
 &lt;br /&gt;
# Populate a dictionary with key-value pair {MD5 hash - [file name]}&lt;br /&gt;
def PopulateSameContent(filePaths, sameContent):&lt;br /&gt;
    for filePath in filePaths:&lt;br /&gt;
        md5 = GetMd5Hash(filePath)&lt;br /&gt;
        fileRelPath = os.path.relpath(filePath, os.getcwd())&lt;br /&gt;
        sameContent[md5] = sameContent.get(md5, []) + [fileRelPath]&lt;br /&gt;
&lt;br /&gt;
# Get the MD5 hash without loading the whole file to memory&lt;br /&gt;
# Break the file in chunks whose size is a multiple of 128&lt;br /&gt;
# This takes advantage of the fact that MD5 has 128-byte digest blocks&lt;br /&gt;
def GetMd5Hash(filePath, blockSize = 2 ** 20):&lt;br /&gt;
    digest = hashlib.md5()&lt;br /&gt;
    with open(filePath, &amp;quot;rb&amp;quot;) as file:&lt;br /&gt;
        for chunk in iter(lambda: file.read(blockSize), b''): &lt;br /&gt;
            digest.update(chunk)&lt;br /&gt;
    return digest.hexdigest()&lt;br /&gt;
&lt;br /&gt;
# Printout the lists of files having same content&lt;br /&gt;
def PrintResults(sameContent):&lt;br /&gt;
    print(&amp;quot;Lists of files having same content:&amp;quot;)&lt;br /&gt;
    for files in sorted(sameContent.values(), key = len, reverse = True):&lt;br /&gt;
        if len(files) &amp;lt; 2: break&lt;br /&gt;
        print(&amp;quot;[{0}]&amp;quot;.format(&amp;quot;, &amp;quot;.join(file for file in files)))&lt;br /&gt;
        &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    sys.exit(Main(sys.argv))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
ecco la mia versione:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import os, hashlib&lt;br /&gt;
&lt;br /&gt;
def fileCurrDir():#restituisce una lista res di file presenti nella directory&lt;br /&gt;
	fcd = os.listdir('.')&lt;br /&gt;
	res = []&lt;br /&gt;
	for ott in fcd:&lt;br /&gt;
		if os.path.isfile('{0}'.format(ott)):res.append(ott)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictsize(fl=fileCurrDir()):#restituisce un dizionario con key filesize e value lista di filenames aventi size di filesize&lt;br /&gt;
	res = {}&lt;br /&gt;
	for f in fl:&lt;br /&gt;
		if os.path.getsize('{0}'.format(f)) in list(res.keys()):res[os.path.getsize('{0}'.format(f))].append(f);continue&lt;br /&gt;
		else:pass&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))] = list()&lt;br /&gt;
		res[os.path.getsize('{0}'.format(f))].append(f)&lt;br /&gt;
	return res&lt;br /&gt;
&lt;br /&gt;
def dictremsa(a=dictsize()):#data un dizionario key::list rimuove tutti gli item la cui len di lista sia unitaria&lt;br /&gt;
	tmp = list(a.keys())&lt;br /&gt;
	for tmpkey in tmp:&lt;br /&gt;
		if len(a[tmpkey]) &amp;lt; 2: a.pop(tmpkey)&lt;br /&gt;
		else:continue&lt;br /&gt;
	return a&lt;br /&gt;
&lt;br /&gt;
def hashcontrolinsl(l1): #data una lista di nomi di file compara l hash di tutte le possibili coppie dentro 	l1&lt;br /&gt;
	while l1 != []:&lt;br /&gt;
		toTest = l1.pop()&lt;br /&gt;
		del res[:]&lt;br /&gt;
		res.append(toTest)&lt;br /&gt;
		for tmp in l1:&lt;br /&gt;
			#res.append(list[toTest,tmp])&lt;br /&gt;
	#return res&lt;br /&gt;
			hasher = hashlib.md5()&lt;br /&gt;
			hasher2 = hashlib.md5()&lt;br /&gt;
			f = open('{0}'.format(toTest), 'rb')&lt;br /&gt;
			toHash = f.read()&lt;br /&gt;
			hasher.update(toHash)&lt;br /&gt;
			toTesthash = hasher.hexdigest()&lt;br /&gt;
			f.close()&lt;br /&gt;
			f = open('{0}'.format(tmp), 'rb')&lt;br /&gt;
			toHash2 = f.read()&lt;br /&gt;
			hasher2.update(toHash2)&lt;br /&gt;
			tmphash = hasher2.hexdigest()&lt;br /&gt;
			if tmphash==toTesthash: #print('{0} e {1}  sono uguali\n'.format(toTest,tmp))&lt;br /&gt;
				res.append(tmp)&lt;br /&gt;
			else:continue&lt;br /&gt;
		if len(res)&amp;gt;1: &lt;br /&gt;
			print(res);res.pop(0)&lt;br /&gt;
			for j in res:&lt;br /&gt;
				l1.pop(l1.index(j))&lt;br /&gt;
		&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def hashcontroltoMajorTom(a=dictremsa()):#fa in modo che vengano &amp;quot;hashate&amp;quot; solo delle liste di file che abbiano passato il &amp;quot;stessadimenzione&amp;quot; test&lt;br /&gt;
	hasher = hashlib.md5()&lt;br /&gt;
	try:&lt;br /&gt;
		obviouslyequal = a.pop(0)&lt;br /&gt;
		print(&amp;quot;i seguenti file hanno lo stesso contenuto... NULLA!!!!!:\n&amp;quot;)&lt;br /&gt;
		for oe in obviouslyequal:&lt;br /&gt;
			print(&amp;quot;{0}&amp;quot;.format(oe))&lt;br /&gt;
	except KeyError:pass&lt;br /&gt;
	values = list(a.values())&lt;br /&gt;
	print(&amp;quot;\ni seguenti file contengono qualcosa ma sono uguali:\n&amp;quot;)&lt;br /&gt;
	for namelist in values:&lt;br /&gt;
		hashcontrolinsl(namelist)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
hashcontroltoMajorTom()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-fede&lt;br /&gt;
&lt;br /&gt;
==Bash==&lt;br /&gt;
Qualche idea per Bash...&amp;lt;br/&amp;gt;&lt;br /&gt;
Si potrebbero usare:&amp;lt;br/&amp;gt;&lt;br /&gt;
Per la dimensione in byte dei &amp;lt;file&amp;gt;:&lt;br /&gt;
 fileSize=$(stat --format=%s &amp;lt;file&amp;gt;)&lt;br /&gt;
Per avere l'output del solo hash md5 (senza l'ausilio di altri comandi):&lt;br /&gt;
 fileHashMd5=$(md5sum &amp;lt;file&amp;gt; | while read fileHash fileName; do echo $fileHash; done)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Fede&amp;amp;Alessio#&lt;br /&gt;
for file in *; do&lt;br /&gt;
	if [[ -f &amp;quot;$file&amp;quot; ]] ; then&lt;br /&gt;
		filesize=$(stat -c%s &amp;quot;$file&amp;quot;)&lt;br /&gt;
		for file2 in *; do&lt;br /&gt;
			if [[ -f &amp;quot;$file2&amp;quot; ]] ; then&lt;br /&gt;
				if [[ &amp;quot;$file&amp;quot; = &amp;quot;$file2&amp;quot; ]]; then &lt;br /&gt;
					continue&lt;br /&gt;
				fi&lt;br /&gt;
				filesize2=$(stat -c%s &amp;quot;$file2&amp;quot;)&lt;br /&gt;
				if [[ $filesize -eq $filesize2 ]]; then&lt;br /&gt;
					diff &amp;quot;$file&amp;quot; &amp;quot;$file2&amp;quot; &amp;amp;&amp;amp; echo &amp;quot;&amp;quot;$file&amp;quot; == &amp;quot;$file2&amp;quot;&amp;quot;  ###&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
#Purtroppo non siamo riusciti a finire e abbiamo optato per una soluzione poco efficiente con un diff, poi continueremo per rendarlà un po migliore&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=752</id>
		<title>ProvaTeorica 2014.02.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=752"/>
		<updated>2014-05-21T09:44:21Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor bbwl {&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktolog;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	int logging = 0;&lt;br /&gt;
	queue q;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write (eltype elem) {&lt;br /&gt;
	if (q.length() == MAXELEM || logging)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
	q.enqueue (elem);&lt;br /&gt;
	logging = 1;&lt;br /&gt;
	oktolog.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry eltype log() {&lt;br /&gt;
	if (q.length == 0)&lt;br /&gt;
		oktolog.wait();&lt;br /&gt;
	eltype tmp = q.top();&lt;br /&gt;
	logging = 0;&lt;br /&gt;
	oktoread.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry eltype read() {&lt;br /&gt;
	if (q.length == 0 || logging)&lt;br /&gt;
		oktoread.wait();&lt;br /&gt;
	eltype tmp = q.dequeue();&lt;br /&gt;
	oktowrite.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Esercizio c.2&lt;br /&gt;
&lt;br /&gt;
alpha(x,y): &amp;lt;x=4, y=sqrt(x)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
il valore che viene salvato in y è sempre 2, quindi non va bene.&lt;br /&gt;
&lt;br /&gt;
bravo(x,y): &amp;lt;y=sqrt(x), x=4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
xi yi xf yf&lt;br /&gt;
0  0  4  0&lt;br /&gt;
0  1  4  1&lt;br /&gt;
1  0  4  1&lt;br /&gt;
1  1  4  1&lt;br /&gt;
&lt;br /&gt;
il valore iniziale di x viene salvato in y, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
charlie(x,y): &amp;lt;y=sqrt(x), x=4*y&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Anche questo va bene, per le stesse ragioni di bravo.&lt;br /&gt;
&lt;br /&gt;
delta(z,t): &amp;lt;z=z xor t, t=z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
zi ti zf tf&lt;br /&gt;
0  0  0  0&lt;br /&gt;
0  1  1  0&lt;br /&gt;
1  0  1  1&lt;br /&gt;
1  1  0  1&lt;br /&gt;
&lt;br /&gt;
Il valore iniziale di z viene salvato in t, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
Esercizio g.1&lt;br /&gt;
&lt;br /&gt;
Sia n=3 il numero di pagine mantenute in memoria&lt;br /&gt;
&lt;br /&gt;
a) 123456789123456789...&lt;br /&gt;
&lt;br /&gt;
MIN = MINNUM&lt;br /&gt;
 11144777&lt;br /&gt;
  2225588&lt;br /&gt;
    333669&lt;br /&gt;
&lt;br /&gt;
b) 145231231231231...&lt;br /&gt;
&lt;br /&gt;
MINNUM&lt;br /&gt;
&lt;br /&gt;
 111232123&lt;br /&gt;
   44444444&lt;br /&gt;
     5555555&lt;br /&gt;
&lt;br /&gt;
MIN&lt;br /&gt;
 111111111&lt;br /&gt;
   44222222&lt;br /&gt;
     5333333&lt;br /&gt;
&lt;br /&gt;
Alessandro&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=751</id>
		<title>ProvaTeorica 2014.02.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=751"/>
		<updated>2014-05-21T09:44:02Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor bbwl {&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktolog;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	int logging = 0;&lt;br /&gt;
	queue q;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write (eltype elem) {&lt;br /&gt;
	if (q.length() == MAXELEM || logging)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
	q.enqueue (elem);&lt;br /&gt;
	logging = 1;&lt;br /&gt;
	oktolog.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry eltype log() {&lt;br /&gt;
	if (q.length == 0)&lt;br /&gt;
		oktolog.wait();&lt;br /&gt;
	eltype tmp = q.top();&lt;br /&gt;
	logging = 0;&lt;br /&gt;
	oktoread.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry eltype read() {&lt;br /&gt;
	if (q.length == 0 || logging)&lt;br /&gt;
		oktoread.wait();&lt;br /&gt;
	eltype tmp = q.dequeue();&lt;br /&gt;
	oktowrite.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Esercizio c.2&lt;br /&gt;
&lt;br /&gt;
alpha(x,y): &amp;lt;x=4, y=sqrt(x)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
il valore che viene salvato in y è sempre 2, quindi non va bene.&lt;br /&gt;
&lt;br /&gt;
bravo(x,y): &amp;lt;y=sqrt(x), x=4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
xi yi xf yf&lt;br /&gt;
0  0  4  0&lt;br /&gt;
0  1  4  1&lt;br /&gt;
1  0  4  1&lt;br /&gt;
1  1  4  1&lt;br /&gt;
&lt;br /&gt;
il valore iniziale di x viene salvato in y, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
charlie(x,y): &amp;lt;y=sqrt(x), x=4*y&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Anche questo va bene, per le stesse ragioni di bravo.&lt;br /&gt;
&lt;br /&gt;
delta(z,t): &amp;lt;z=z xor t, t=z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
zi ti zf tf&lt;br /&gt;
0  0  0  0&lt;br /&gt;
0  1  1  0&lt;br /&gt;
1  0  1  1&lt;br /&gt;
1  1  0  1&lt;br /&gt;
&lt;br /&gt;
Il valore iniziale di z viene salvato in t, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
Esercizio g.1&lt;br /&gt;
&lt;br /&gt;
Sia n=3 il numero di pagine mantenute in memoria&lt;br /&gt;
&lt;br /&gt;
a) 123456789123456789&lt;br /&gt;
&lt;br /&gt;
MIN = MINNUM&lt;br /&gt;
 11144777&lt;br /&gt;
  2225588&lt;br /&gt;
    333669&lt;br /&gt;
&lt;br /&gt;
b) 145231231231231...&lt;br /&gt;
&lt;br /&gt;
MINNUM&lt;br /&gt;
&lt;br /&gt;
 111232123&lt;br /&gt;
   44444444&lt;br /&gt;
     5555555&lt;br /&gt;
&lt;br /&gt;
MIN&lt;br /&gt;
 111111111&lt;br /&gt;
   44222222&lt;br /&gt;
     5333333&lt;br /&gt;
&lt;br /&gt;
Alessandro&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=750</id>
		<title>ProvaTeorica 2014.02.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=750"/>
		<updated>2014-05-21T09:42:08Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor bbwl {&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktolog;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	int logging = 0;&lt;br /&gt;
	queue q;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write (eltype elem) {&lt;br /&gt;
	if (q.length() == MAXELEM || logging)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
	q.enqueue (elem);&lt;br /&gt;
	logging = 1;&lt;br /&gt;
	oktolog.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry eltype log() {&lt;br /&gt;
	if (q.length == 0)&lt;br /&gt;
		oktolog.wait();&lt;br /&gt;
	eltype tmp = q.top();&lt;br /&gt;
	logging = 0;&lt;br /&gt;
	oktoread.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry eltype read() {&lt;br /&gt;
	if (q.length == 0 || logging)&lt;br /&gt;
		oktoread.wait();&lt;br /&gt;
	eltype tmp = q.dequeue();&lt;br /&gt;
	oktowrite.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Esercizio c.2&lt;br /&gt;
&lt;br /&gt;
alpha(x,y): &amp;lt;x=4, y=sqrt(x)&amp;gt;&lt;br /&gt;
&lt;br /&gt;
il valore che viene salvato in y è sempre 2, quindi non va bene.&lt;br /&gt;
&lt;br /&gt;
bravo(x,y): &amp;lt;y=sqrt(x), x=4&amp;gt;&lt;br /&gt;
&lt;br /&gt;
xi yi xf yf&lt;br /&gt;
0  0  4  0&lt;br /&gt;
0  1  4  1&lt;br /&gt;
1  0  4  1&lt;br /&gt;
1  1  4  1&lt;br /&gt;
&lt;br /&gt;
il valore iniziale di x viene salvato in y, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
charlie(x,y): &amp;lt;y=sqrt(x), x=4*y&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Anche questo va bene, per le stesse ragioni di bravo.&lt;br /&gt;
&lt;br /&gt;
delta(z,t): &amp;lt;z=z xor t, t=z xor t&amp;gt;&lt;br /&gt;
&lt;br /&gt;
zi ti zf tf&lt;br /&gt;
0  0  0  0&lt;br /&gt;
0  1  1  0&lt;br /&gt;
1  0  1  1&lt;br /&gt;
1  1  0  1&lt;br /&gt;
&lt;br /&gt;
Il valore iniziale di z viene salvato in t, quindi va bene.&lt;br /&gt;
&lt;br /&gt;
Esercizio g.1&lt;br /&gt;
&lt;br /&gt;
Sia n=3 il numero di pagine mantenute in memoria&lt;br /&gt;
a) 123456789123456789&lt;br /&gt;
&lt;br /&gt;
MIN = MINNUM&lt;br /&gt;
11144777&lt;br /&gt;
  2225588&lt;br /&gt;
    333669&lt;br /&gt;
&lt;br /&gt;
b) 145231231231231...&lt;br /&gt;
&lt;br /&gt;
MINNUM&lt;br /&gt;
&lt;br /&gt;
111232123&lt;br /&gt;
  44444444&lt;br /&gt;
    5555555&lt;br /&gt;
&lt;br /&gt;
MIN&lt;br /&gt;
111111111&lt;br /&gt;
  44222222&lt;br /&gt;
    5333333&lt;br /&gt;
&lt;br /&gt;
Alessandro&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=749</id>
		<title>ProvaTeorica 2014.02.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=749"/>
		<updated>2014-05-21T08:25:36Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor bbwl {&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktolog;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	int logging = 0;&lt;br /&gt;
	queue q;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write (eltype elem) {&lt;br /&gt;
	if (q.length() == MAXELEM || logging)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
	q.enqueue (elem);&lt;br /&gt;
	logging = 1;&lt;br /&gt;
	oktolog.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry eltype log() {&lt;br /&gt;
	if (q.length == 0)&lt;br /&gt;
		oktolog.wait();&lt;br /&gt;
	eltype tmp = q.top();&lt;br /&gt;
	logging = 0;&lt;br /&gt;
	oktoread.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry eltype read() {&lt;br /&gt;
	if (q.length == 0 || logging)&lt;br /&gt;
		oktoread.wait();&lt;br /&gt;
	eltype tmp = q.dequeue();&lt;br /&gt;
	oktowrite.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alessandro&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=748</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=748"/>
		<updated>2014-05-21T08:25:10Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.02.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.07.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.02.14]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2005.11.04]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.01.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.05.30]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=747</id>
		<title>ProvaTeorica 2014.02.22</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2014.02.22&amp;diff=747"/>
		<updated>2014-05-21T08:12:25Z</updated>

		<summary type="html">&lt;p&gt;Coci: Created page with &amp;quot;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]  Esercizio c.1  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; monitor bbwl { 	condition oktowrite; 	condition oktolog; 	condi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/compiti/2014.02.21.tot.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio c.1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor bbwl {&lt;br /&gt;
	condition oktowrite;&lt;br /&gt;
	condition oktolog;&lt;br /&gt;
	condition oktoread;&lt;br /&gt;
	int logging = 0;&lt;br /&gt;
	queue q;&lt;br /&gt;
	&lt;br /&gt;
	procedure entry write (eltype elem) {&lt;br /&gt;
	if (q.length() == MAXELEM || logging)&lt;br /&gt;
			oktowrite.wait();&lt;br /&gt;
	q.enqueue (elem);&lt;br /&gt;
	logging = 1;&lt;br /&gt;
	oktolog.signal();&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	procedure entry eltype log() {&lt;br /&gt;
	if (q.length == 0)&lt;br /&gt;
		oktolog.wait();&lt;br /&gt;
	eltype tmp = q.top();&lt;br /&gt;
	logging = 0;&lt;br /&gt;
	oktoread.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	procedure entry eltype read() {&lt;br /&gt;
	if (q.length == 0 || logging)&lt;br /&gt;
		oktoread.wait();&lt;br /&gt;
	eltype tmp = q.dequeue();&lt;br /&gt;
	oktowrite.signal();&lt;br /&gt;
	return tmp;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=746</id>
		<title>ProvaPratica 2012.07.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=746"/>
		<updated>2014-05-20T15:02:46Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang = &amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define BUF_SIZE 20&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char** argv){&lt;br /&gt;
	int ncopie, i, ris;&lt;br /&gt;
	char command[BUF_SIZE];&lt;br /&gt;
	if (argc&amp;lt;3) {printf(&amp;quot;inserisci due o più argomenti (ncopie, command)\n&amp;quot;); exit(1);}&lt;br /&gt;
	ncopie = atoi(argv[1]);&lt;br /&gt;
	strcpy(command, argv[2]);&lt;br /&gt;
	for (i = 0; i&amp;lt;ncopie; i++){&lt;br /&gt;
		if(fork()){//processo padre&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			char *env_el;&lt;br /&gt;
			env_el = malloc(BUF_SIZE);&lt;br /&gt;
			sprintf(env_el, &amp;quot;NCOPIA=%d&amp;quot;, i);&lt;br /&gt;
			//asprintf &lt;br /&gt;
			//devo aggiungerci in fondo lo zero terminatore&lt;br /&gt;
			char *newenviron[] = {env_el, (char*) 0};&lt;br /&gt;
			//argv+2 sono gli argomenti, ovvero tutti gli argomenti passati dopo il secondo			&lt;br /&gt;
			ris = execve(argv[2], argv+2, newenviron);&lt;br /&gt;
			if (ris == -1) {perror(&amp;quot;execve&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	for (i = 0; i&amp;lt;ncopie; i++) wait(NULL);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Alessandro&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#define BUF_SIZE 20&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char** argv){&lt;br /&gt;
				int ncopie, i, ris;&lt;br /&gt;
				char command[BUF_SIZE];&lt;br /&gt;
				if (argc&amp;lt;3) {printf(&amp;quot;inserisci due argomenti (ncopie, command)\n&amp;quot;); exit(1);}&lt;br /&gt;
				ncopie = atoi(argv[1]);&lt;br /&gt;
				int fd[ncopie];&lt;br /&gt;
				pid_t pid[ncopie];&lt;br /&gt;
				for (i = 0; i&amp;lt;ncopie; i++){&lt;br /&gt;
								char *tmpfile;&lt;br /&gt;
								asprintf(&amp;amp;tmpfile,&amp;quot;/tmp/ncopie.%d.%d&amp;quot;,getpid(),i);&lt;br /&gt;
								fd[i]=open(tmpfile,O_CREAT|O_RDWR,0600);&lt;br /&gt;
								unlink(tmpfile);&lt;br /&gt;
								if((pid[i]=fork())==0){//processo padre&lt;br /&gt;
												char *NCOPIA;&lt;br /&gt;
												asprintf(&amp;amp;NCOPIA, &amp;quot;NCOPIA=%d&amp;quot;, i); &lt;br /&gt;
												char *newenviron[] = { NCOPIA, (void *)0};	&lt;br /&gt;
												dup2(fd[i],STDOUT_FILENO);&lt;br /&gt;
												ris = execve(argv[2], argv+2, newenviron);&lt;br /&gt;
												if (ris == -1) {perror(&amp;quot;execve&amp;quot;); exit(1);}&lt;br /&gt;
								}&lt;br /&gt;
				}&lt;br /&gt;
				for (i = 0; i&amp;lt;ncopie; i++) {&lt;br /&gt;
								waitpid(pid[i],NULL,0);&lt;br /&gt;
								lseek(fd[i],SEEK_SET,0);&lt;br /&gt;
								char *buf[1024];&lt;br /&gt;
								int n;&lt;br /&gt;
								while ((n=read(fd[i],buf,1024))&amp;gt;0)&lt;br /&gt;
												write(STDOUT_FILENO,buf,n);&lt;br /&gt;
				}&lt;br /&gt;
&lt;br /&gt;
				return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.05.30&amp;diff=742</id>
		<title>ProvaTeorica 2013.05.30</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaTeorica_2013.05.30&amp;diff=742"/>
		<updated>2014-05-19T16:00:12Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;h1&amp;gt;[http://www.cs.unibo.it/~renzo/so/compiti/2013.05.30.tot.pdf Testo del compito]&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio c.1&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor eventp {&lt;br /&gt;
	typedef struct EP {&lt;br /&gt;
		unsigned int value;&lt;br /&gt;
		condition okNotNull;&lt;br /&gt;
		condition okToaAdd;&lt;br /&gt;
		intqueue q;&lt;br /&gt;
	} EP;&lt;br /&gt;
procedure entry EP* create (unsigned value){&lt;br /&gt;
	if (d.value+value &amp;gt; MAXINT || !d.queue.isEmpty()) {&lt;br /&gt;
		d.q.enqueue(value);&lt;br /&gt;
		d.okToAdd.wait();&lt;br /&gt;
		d.q.dequeue();&lt;br /&gt;
	}&lt;br /&gt;
	d.value = d.value + value;&lt;br /&gt;
	if (d.q.top() + value &amp;lt;= d.value.size()) //se il suo valore proposto non causa l’overflow del counter, sblocco lo scrittore successivo&lt;br /&gt;
			d.okToAdd.signal();&lt;br /&gt;
	else&lt;br /&gt;
		d.okNotNull.signal();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry unsigned int read (EP* ep){&lt;br /&gt;
	if (!ep.value)&lt;br /&gt;
		ep.okNotNull.wait();&lt;br /&gt;
	unsigned int toReturn = ep.value;&lt;br /&gt;
	ep.value = 0;&lt;br /&gt;
	ep.okToAdd.signal();&lt;br /&gt;
	return toReturn;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry close(EP * ep){&lt;br /&gt;
	free(ep);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.1&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;lt;b&amp;gt;PUNTO A:&amp;lt;/b&amp;gt; (7+256+(256^2)+(256^3))*1kb =16.843.015kb quindi approssimativamente 16MB&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt; &amp;lt;b&amp;gt; PUNTO B:&amp;lt;/B&amp;gt; blocco indiretto triplo -&amp;gt; primo livello di idirizzamento 256 esimo blocco -&amp;gt; secondo livello di indirizzamento 256 esimo blocco -&amp;gt; terzo livello di indirizzamento al blocco 100000. Qundi in totale 4 blocchi &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt; Esercizio g.2 &amp;lt;/h2&amp;gt;&lt;br /&gt;
[[File:Holt.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
monitor eventp&lt;br /&gt;
{&lt;br /&gt;
	typedef struct EP &lt;br /&gt;
	{&lt;br /&gt;
		unsigned int value;	&lt;br /&gt;
		condition okNotNull;&lt;br /&gt;
		condition okToAdd;&lt;br /&gt;
		intqueue q;&lt;br /&gt;
		}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry EP* create(unsigned value)&lt;br /&gt;
{&lt;br /&gt;
	EP *ep = new EP(value);&lt;br /&gt;
	eps.enqueu(ep);&lt;br /&gt;
	return ep;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
procedure entry write(EP *d,unsigned value)&lt;br /&gt;
{&lt;br /&gt;
	if(d.value+value &amp;gt; d.value.size()|| !d.q.empty()) {&lt;br /&gt;
		d.q.enqueue(value);&lt;br /&gt;
		d.okToAdd.wait();&lt;br /&gt;
		d.q.dequeue();&lt;br /&gt;
	}&lt;br /&gt;
	d.value = d.value + value;&lt;br /&gt;
	if (d.q.top()+value &amp;lt;= d.value.size())&lt;br /&gt;
		d.okToAdd.signal();&lt;br /&gt;
	else&lt;br /&gt;
		d.okNotNull.signal();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// MAXINT - currentvalue &amp;lt; value &lt;br /&gt;
procedure entry unsigned int read(EP *ep)&lt;br /&gt;
{&lt;br /&gt;
	if(!ep.value)&lt;br /&gt;
		ep.okNotNull.wait();&lt;br /&gt;
	unsigned int toReturn = ep.value;&lt;br /&gt;
	ep.value = 0;&lt;br /&gt;
	ep.okToAdd.signal();&lt;br /&gt;
	return toReturn;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=738</id>
		<title>ProvaPratica 2012.07.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=738"/>
		<updated>2014-05-19T14:06:54Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang = &amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define BUF_SIZE 20&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char** argv){&lt;br /&gt;
	int ncopie, i, ris;&lt;br /&gt;
	char command[BUF_SIZE];&lt;br /&gt;
	if (argc&amp;lt;3) {printf(&amp;quot;inserisci due o più argomenti (ncopie, command)\n&amp;quot;); exit(1);}&lt;br /&gt;
	ncopie = atoi(argv[1]);&lt;br /&gt;
	strcpy(command, argv[2]);&lt;br /&gt;
	for (i = 0; i&amp;lt;ncopie; i++){&lt;br /&gt;
		if(fork()){//processo padre&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			char *env_el;&lt;br /&gt;
			env_el = malloc(BUF_SIZE);&lt;br /&gt;
			sprintf(env_el, &amp;quot;NCOPIA=%d&amp;quot;, i);&lt;br /&gt;
			//asprintf &lt;br /&gt;
			//devo aggiungerci in fondo lo zero terminatore&lt;br /&gt;
			char *newenviron[] = {env_el, (char*) 0};&lt;br /&gt;
			//argv+2 sono gli argomenti, ovvero tutti gli argomenti passati dopo il secondo			&lt;br /&gt;
			ris = execve(argv[2], argv+2, newenviron);&lt;br /&gt;
			if (ris == -1) {perror(&amp;quot;execve&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	for (i = 0; i&amp;lt;ncopie; i++) wait(NULL);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Alessandro&lt;br /&gt;
(In realtà non funziona bene, di fatto un processo fa quello che dovrebbe fare e gli altri danno bad address, se trovate l'errore correggetelo e scrivete qua sotto cosa avete cambiato e perché)&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=737</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=737"/>
		<updated>2014-05-19T12:35:31Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.07.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.02.14]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2005.11.04]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.01.19]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=736</id>
		<title>ProvaPratica 2012.07.17</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.07.17&amp;diff=736"/>
		<updated>2014-05-19T12:32:45Z</updated>

		<summary type="html">&lt;p&gt;Coci: Created page with &amp;quot;&amp;lt;syntaxhighlight lang = &amp;quot;C&amp;quot;&amp;gt; #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;unistd.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;string.h&amp;gt; #define BUF_SIZE 20  int main(int argc, char** argv){ 	int ncopie, ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;syntaxhighlight lang = &amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define BUF_SIZE 20&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char** argv){&lt;br /&gt;
	int ncopie, i, ris;&lt;br /&gt;
	char NCOPIA[BUF_SIZE];&lt;br /&gt;
	char command[BUF_SIZE];&lt;br /&gt;
	if (argc!=3) {printf(&amp;quot;inserisci due argomenti (ncopie, command)\n&amp;quot;); exit(1);}&lt;br /&gt;
	ncopie = atoi(argv[1]);&lt;br /&gt;
	strcpy(command, argv[2]);&lt;br /&gt;
	for (i = 0; i&amp;lt;ncopie; i++){&lt;br /&gt;
		if(fork()){//processo padre&lt;br /&gt;
		}&lt;br /&gt;
		else {&lt;br /&gt;
			char *NCOPIA;&lt;br /&gt;
			NCOPIA = malloc(BUF_SIZE);&lt;br /&gt;
			sprintf(NCOPIA, &amp;quot;%d&amp;quot;, i); &lt;br /&gt;
			char *newenviron[] = { NCOPIA};	&lt;br /&gt;
			ris = execve(command, NULL, newenviron);&lt;br /&gt;
			if (ris == -1) {perror(&amp;quot;execve&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
	}&lt;br /&gt;
	wait(NULL);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Alessandro&lt;br /&gt;
(In realtà non funziona bene, di fatto un processo fa quello che dovrebbe fare e gli altri danno bad address, se trovate l'errore correggetelo e scrivete qua sotto cosa avete cambiato e perché)&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=735</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Main_Page&amp;diff=735"/>
		<updated>2014-05-19T12:26:54Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Questo &amp;amp;egrave; il Wiki del Corso di Sistemi Operativi&lt;br /&gt;
&lt;br /&gt;
[[Esercizi a caso del Prof.]]&lt;br /&gt;
&lt;br /&gt;
[[Decalogo di Programmazione Concorrente]]&lt;br /&gt;
&lt;br /&gt;
[[Python Programma tieni punteggio.]]&lt;br /&gt;
&lt;br /&gt;
[[Comandi visti alle lezioni.]]&lt;br /&gt;
&lt;br /&gt;
[[SYS CALL viste a lezione.]]&lt;br /&gt;
&lt;br /&gt;
[[Parametri con getopt().]]&lt;br /&gt;
&lt;br /&gt;
[[Funzione con numero variabile di parametri.]]&lt;br /&gt;
&lt;br /&gt;
[[stampf - implementazione ridotta della printf.]]&lt;br /&gt;
&lt;br /&gt;
[[Producer&amp;amp;Consumer MP.]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2014.01.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.09.13]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.07.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.05.29]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2013.01.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.09.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2005.02.10]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2011.07.25]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.02.09]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.05.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.06.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2012.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2013.02.15]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica_2011.02.11]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.01.24]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2014.01.22]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2012.07.16]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica_2010.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.01.16]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2009.09.18]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2008.09.17]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.09.07]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2013.06.21]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.02.03]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.09.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.02.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.01.15]]&lt;br /&gt;
&lt;br /&gt;
[[Prova Teorica 2007.07.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2011.01.17]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2010.05.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria 2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.09.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2012.06.20]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2010.07.19]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.05.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2009.01.30]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeoria_2012.01.12]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2009.06.23]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2013.02.14]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaTeorica 2005.11.04]]&lt;br /&gt;
&lt;br /&gt;
[[ProvaPratica 2011.01.19]]&lt;br /&gt;
----&lt;br /&gt;
Ricordate che per creare un account o quando viene richiesto di risolvere un semplice calcolo occorre ricordare quanto scritto [[qui]]&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.09.19&amp;diff=733</id>
		<title>ProvaPratica 2012.09.19</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2012.09.19&amp;diff=733"/>
		<updated>2014-05-16T10:03:04Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
URL-&amp;gt; http://www.cs.unibo.it/~renzo/so/pratiche/2012.09.19.pdf&lt;br /&gt;
----&lt;br /&gt;
[C Esercizio 1]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;signal.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;limits.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFSIZE 1024&lt;br /&gt;
&lt;br /&gt;
long int n = 0;&lt;br /&gt;
&lt;br /&gt;
void handler(int sig_num){&lt;br /&gt;
&lt;br /&gt;
	signal(SIGUSR1, handler);&lt;br /&gt;
	fprintf(stderr, &amp;quot;\n%ld Bytes copied until now\n&amp;quot;, n);&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
&lt;br /&gt;
	int nread, nwritten,&lt;br /&gt;
	    i = 0;&lt;br /&gt;
	char buffer[BUFSIZE],&lt;br /&gt;
	     cool_gui[] = &amp;quot;-\\|/&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	signal(SIGUSR1, handler);&lt;br /&gt;
	fprintf(stderr, &amp;quot;Copying   &amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	while( (nread = read(STDIN_FILENO, buffer, BUFSIZE)) != 0 ){&lt;br /&gt;
		if(nread &amp;lt; 0){&lt;br /&gt;
			perror(&amp;quot;Read error: &amp;quot;);&lt;br /&gt;
			exit(EXIT_FAILURE);&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		nwritten = write(STDOUT_FILENO, buffer, nread);&lt;br /&gt;
                if(nwritten &amp;lt; 0){&lt;br /&gt;
                        perror(&amp;quot;Write error: &amp;quot;);&lt;br /&gt;
                        exit(EXIT_FAILURE);&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
		n += nwritten&lt;br /&gt;
		fprintf(stderr, &amp;quot;\b\b%c &amp;quot;,cool_gui[i%4]);&lt;br /&gt;
		(i == INT_MAX) ? (i=0) : (i++); 	&lt;br /&gt;
	}&lt;br /&gt;
			&lt;br /&gt;
	fprintf(stderr, &amp;quot;\nDone\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
	return EXIT_SUCCESS;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Eduardo&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;signal.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/eventfd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
uint64_t counter = 0;&lt;br /&gt;
int seconds = 1;&lt;br /&gt;
&lt;br /&gt;
void sig_handler(int signo){	&lt;br /&gt;
		double ratio = (double) counter / (double) seconds;&lt;br /&gt;
		fprintf(stderr, &amp;quot;Finora sono stati scritti %lf byte/s\n&amp;quot;, ratio);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(){&lt;br /&gt;
	int efd;&lt;br /&gt;
	int anim_counter = 0;&lt;br /&gt;
	char buf;&lt;br /&gt;
	char animation[] = {'-','\\', '|', '/' };&lt;br /&gt;
	signal(SIGUSR1, sig_handler);&lt;br /&gt;
	efd = eventfd(0, 0);&lt;br /&gt;
	fprintf(stderr, &amp;quot; &amp;quot;);&lt;br /&gt;
	if(fork()){//processo nonno&lt;br /&gt;
		while(1){&lt;br /&gt;
		fprintf(stderr, &amp;quot;\b%c&amp;quot;, animation[anim_counter]);&lt;br /&gt;
		anim_counter = (anim_counter+1)%4;&lt;br /&gt;
		usleep(100000);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	else {&lt;br /&gt;
		if(fork()){//padre	&lt;br /&gt;
			while(read(STDIN_FILENO, &amp;amp;buf, 1)){&lt;br /&gt;
				write(STDOUT_FILENO, &amp;amp;buf, 1);&lt;br /&gt;
				write(efd, &amp;amp;counter, sizeof(uint64_t));&lt;br /&gt;
				counter++;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		else {//nipote&lt;br /&gt;
			sleep(1);&lt;br /&gt;
			while( read(efd, &amp;amp;counter, sizeof(uint64_t)) ){&lt;br /&gt;
				fprintf(stderr, &amp;quot;\n%ds: %llu bytes\n&amp;quot;,seconds, counter);&lt;br /&gt;
				seconds++;&lt;br /&gt;
				sleep(1);&lt;br /&gt;
				}&lt;br /&gt;
			}	&lt;br /&gt;
	wait(NULL);&lt;br /&gt;
	}&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
-Coci (avevo provato a farlo con la pipe, ma dava dei problemi)&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
[Bash Esercizio 3]&lt;br /&gt;
In due versioni:&amp;lt;br&amp;gt;&lt;br /&gt;
1. one-liner, per amore di leggibilità&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
 IFS=$(echo -ne &amp;quot;\n\b&amp;quot;) &amp;amp;&amp;amp; file `find $DIRECTORY` | sed -rn &amp;quot;s/(.*):\ +`file -b $FILENAME`/\1/p&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Purtroppo se esistono troppi file nell'albero della directory non funziona (Argument list too long)&amp;lt;br&amp;gt;&lt;br /&gt;
2. script&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
SUCCESS=0&lt;br /&gt;
FAILURE=1&lt;br /&gt;
&lt;br /&gt;
#Check arguments&lt;br /&gt;
if [[ $# -ne 2 ]]&lt;br /&gt;
then&lt;br /&gt;
	echo &amp;quot;Usage: `basename $0` file directory&amp;quot;&lt;br /&gt;
	exit $FAILURE&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
IFS=$(echo -e &amp;quot;\n\b&amp;quot;)        #set newline as separator&lt;br /&gt;
file_type=$(file -b $1)&lt;br /&gt;
file_list=$(find $2) &lt;br /&gt;
&lt;br /&gt;
for item in $file_list&lt;br /&gt;
do&lt;br /&gt;
	item_type=$(file -b $item)&lt;br /&gt;
	if [[ $item_type == $file_type ]]&lt;br /&gt;
	then&lt;br /&gt;
		echo $item&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
exit $SUCCESS&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
La riga di codice per settare il separatore l'ho trovata qui: http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html . Non mi è chiaro perchè il separatore debba essere &amp;quot;\n\b&amp;quot; e non solo &amp;quot;\n&amp;quot;, ma ho provato in varie salse, e questo è l'unico modo in cui lo script funziona.&amp;lt;br&amp;gt;&lt;br /&gt;
-Eduardo&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2014.01.23&amp;diff=706</id>
		<title>ProvaPratica 2014.01.23</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2014.01.23&amp;diff=706"/>
		<updated>2014-05-10T14:02:52Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[C esercizi 1 e 2]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
*Esercizio 1: Linguaggio C (obbligatorio): (20 punti)&lt;br /&gt;
*Scrivere un programma in C “linean” che prenda come parametro il pathname di un file e un numero intero (che chiameremo n). &lt;br /&gt;
*Il programma deve stampare come output il numero di caratteri presenti nella n-ma riga del file se il file e' un file regolare di testo, non deve stampare nulla negli altri casi.&lt;br /&gt;
*Un file viene considerato di testo se tutti i suoi byte hanno valori compresi nel range 1-127.&lt;br /&gt;
*Per controllare se il file e' “regolare” usare la system call lstat&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 200&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd ){                                   //check if the file is a regular file of text,it means that every byte has a value between 1-127&lt;br /&gt;
	int c;&lt;br /&gt;
	while ( (c = getc ( fd ) ) != EOF &amp;amp;&amp;amp; c &amp;lt;= 127 );&lt;br /&gt;
	rewind(fd);                                           //sets the file's cursor at the beginning,otherwise the linean program cannot find the line&lt;br /&gt;
	return ( (c == EOF)? 1 : 0 );&lt;br /&gt;
}&lt;br /&gt;
	 &lt;br /&gt;
		&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void linean( char *path , int line ){&lt;br /&gt;
	FILE *fd;&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	char bufline[BUFFSIZE];&lt;br /&gt;
	char *res;&lt;br /&gt;
	int n = line;&lt;br /&gt;
	res = NULL;&lt;br /&gt;
	lstat( path , &amp;amp;buf );&lt;br /&gt;
	if ( S_ISREG( buf.st_mode ) )&lt;br /&gt;
	{&lt;br /&gt;
		fd = fopen( path , &amp;quot;r&amp;quot; );&lt;br /&gt;
		if ( fd == NULL )&lt;br /&gt;
		{&lt;br /&gt;
			perror( &amp;quot;Error to open the file\n&amp;quot; );&lt;br /&gt;
			exit(1);&lt;br /&gt;
		}&lt;br /&gt;
			if ( istextfile( fd ) )&lt;br /&gt;
			{&lt;br /&gt;
				while ( ( line &amp;gt; 0 ) )                                        //iterates until at the nline and when is reached then checks if the buffer contains something&lt;br /&gt;
				{&lt;br /&gt;
					res = fgets(bufline, BUFFSIZE , fd );    //every time the nline is buffered,when exits from the cicle, the buffer contains the nline &lt;br /&gt;
					line--;&lt;br /&gt;
				}&lt;br /&gt;
				if ( res != NULL )                &lt;br /&gt;
				{&lt;br /&gt;
					printf( &amp;quot;The file %s in line %d has : %d char\n&amp;quot; , path , n , ( strlen( bufline ) - 1 )  );  //strlen also consider the carriage return&lt;br /&gt;
				}&lt;br /&gt;
				else&lt;br /&gt;
				printf( &amp;quot;Error: isn't possible to find the line\n&amp;quot; );&lt;br /&gt;
			}&lt;br /&gt;
			else&lt;br /&gt;
				printf( &amp;quot;Error is not a regular file of text\n&amp;quot; );&lt;br /&gt;
				&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
				&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
		printf( &amp;quot;The file %s isn't a regular file\n&amp;quot; , path );&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
int main( int argc , char *argv[] ){&lt;br /&gt;
	int n = atoi( argv[2] );&lt;br /&gt;
	linean( argv[1] , n );&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
*Esercizio 2: completamento (10 punti)&lt;br /&gt;
*Si scriva un programma C chiamato “lineandir”. Il risultato del programma, stampato su standard output, deve essere un solo&lt;br /&gt;
*numero intero: la somma del numero di caratteri presenti nelle n-me righe di tutti i file regolari, di testo, non nascosti (il primo&lt;br /&gt;
*carattere deve essere diverso da punto) della directory corrente. &lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 200&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd );&lt;br /&gt;
int linean( char *path , int line );&lt;br /&gt;
void lineandir( char *dir , int line );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void lineandir( char *dir , int line ){&lt;br /&gt;
	int count , i;&lt;br /&gt;
	int sumline;&lt;br /&gt;
	struct dirent **de;&lt;br /&gt;
	sumline = 0;&lt;br /&gt;
	count = scandir( dir , &amp;amp;de , NULL , alphasort );&lt;br /&gt;
	for ( i = 0 ; i &amp;lt; count ; i++ )&lt;br /&gt;
	{&lt;br /&gt;
		if ( de[i]-&amp;gt;d_name[0] != '.' )     //doesn't consider the hidden files&lt;br /&gt;
			sumline = sumline + linean( de[i]-&amp;gt;d_name , line );&lt;br /&gt;
		free(de[i]);&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;The sum of char for every regular text file's nline in the current directory is: %d\n&amp;quot; , sumline );&lt;br /&gt;
	free(de);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd ){                                  &lt;br /&gt;
	int c;&lt;br /&gt;
	while ( (c = getc ( fd ) ) != EOF &amp;amp;&amp;amp; c &amp;lt;= 127 );&lt;br /&gt;
	rewind(fd);                                           &lt;br /&gt;
	return ( (c == EOF)? 1 : 0 );&lt;br /&gt;
}&lt;br /&gt;
	 &lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*linean is modified so it can return the value of the char in the nline */&lt;br /&gt;
int linean( char *path , int line ){&lt;br /&gt;
	FILE *fd;&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	char bufline[BUFFSIZE];&lt;br /&gt;
	char *res;&lt;br /&gt;
	int n = line;&lt;br /&gt;
	res = NULL;&lt;br /&gt;
	lstat( path , &amp;amp;buf );&lt;br /&gt;
	if ( S_ISREG( buf.st_mode ) )&lt;br /&gt;
	{&lt;br /&gt;
		fd = fopen( path , &amp;quot;r&amp;quot; );&lt;br /&gt;
		if ( fd == NULL )&lt;br /&gt;
		{&lt;br /&gt;
			perror( &amp;quot;Error to open the file\n&amp;quot; );&lt;br /&gt;
			exit(1);&lt;br /&gt;
		}&lt;br /&gt;
			if ( istextfile( fd ) )&lt;br /&gt;
			{&lt;br /&gt;
				while ( ( line &amp;gt; 0 ) )                                        &lt;br /&gt;
				{&lt;br /&gt;
					res = fgets(bufline, BUFFSIZE , fd );    &lt;br /&gt;
					line--;&lt;br /&gt;
				}&lt;br /&gt;
				if ( res != NULL )                &lt;br /&gt;
				{&lt;br /&gt;
					return( ( strlen( bufline ) - 1 )  );  &lt;br /&gt;
				}&lt;br /&gt;
				else&lt;br /&gt;
				printf( &amp;quot;Error: isn't possible to find the line\n&amp;quot; );&lt;br /&gt;
			}&lt;br /&gt;
			else&lt;br /&gt;
				printf( &amp;quot;Error is not a regular file of text\n&amp;quot; );&lt;br /&gt;
				&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
				&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
		printf( &amp;quot;The file %s isn't a regular file\n&amp;quot; , path );&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
int main( int argc , char *argv[] ){&lt;br /&gt;
	int n = atoi( argv[1] );&lt;br /&gt;
	lineandir( &amp;quot;./&amp;quot; , n );&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[Bash esercizio 3]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
#Il comando che dovrete implementare come script shell o programma python e' updatedir. Updatedir prende due directorycome parametri.&lt;br /&gt;
#updatedir dira dirb deve copiare in dirb tutti i file regolari che sono in dira e non in dirb. Se un file regolare e' presente con lo stesso nome sia in&lt;br /&gt;
#dira sia in dirb, il file deve essere copiato dalla dira alla dirb solo se i contenuti differiscono.&lt;br /&gt;
&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for file in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	if [[ -f $file ]] ; then          #checks if the file is regular&lt;br /&gt;
		thereisnotfile=1          #variable that identify if the file is also in dir2&lt;br /&gt;
		for file2 in &amp;quot;$2&amp;quot;/*; do&lt;br /&gt;
			if [[ -f $file2 ]] ; then&lt;br /&gt;
				if [[  $file2 !=  $file ]] ; then      #checks if the file is only in dir1 and not in dir2&lt;br /&gt;
					continue&lt;br /&gt;
				else&lt;br /&gt;
					thereisnotfile=0            #the file is in both dir&lt;br /&gt;
				fi&lt;br /&gt;
				if [[ $thereisnotfile -eq 0 ]]; then      &lt;br /&gt;
					if [[ $(md5sum &amp;quot;$file&amp;quot;) != $(md5sum &amp;quot;$file2&amp;quot;) ]] ; then   #checks if the file in dir1 is different of file in dir2 by md5sum &lt;br /&gt;
						bn=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
						cp $file  &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
						thereisnotfile=2        #is set in this way for not continue to iterate&lt;br /&gt;
					fi&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
		if [[ $thereisnotfile -eq 1 ]]; then&lt;br /&gt;
			bn=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
			cp $file  &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;		&lt;br /&gt;
Pirata&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function usage {&lt;br /&gt;
  command=$(basename &amp;quot;$0&amp;quot;)&lt;br /&gt;
  echo &amp;quot;Usage: $command source destination&amp;quot;&lt;br /&gt;
  exit 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ ! -d $1 ]]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;Source is not a dir&amp;quot;&lt;br /&gt;
  usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -d $2 ]]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;Destination is not a dir&amp;quot;&lt;br /&gt;
  usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
find $1 -type f -print0 | while IFS= read -r -d $'\0' file; do&lt;br /&gt;
  filename=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
  if [[ -f &amp;quot;$2$filename&amp;quot; ]]&lt;br /&gt;
  then&lt;br /&gt;
  	  cp &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  	  if cmp -s &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  	  then&lt;br /&gt;
  	  	  /* Do nothing are the same */&lt;br /&gt;
  	  else&lt;br /&gt;
  	  	  cp &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  	  fi&lt;br /&gt;
  fi	  &lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Mrta&lt;br /&gt;
&lt;br /&gt;
[Esercizio 1]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#define PATH_LEN 100&lt;br /&gt;
#define BUF_LEN 200&lt;br /&gt;
&lt;br /&gt;
printLine(char *path, int n){&lt;br /&gt;
		FILE* fd;&lt;br /&gt;
		char line[BUF_LEN];&lt;br /&gt;
		char* res;&lt;br /&gt;
		fd = fopen(path, &amp;quot;r&amp;quot;);&lt;br /&gt;
		if (fd == NULL) {perror(&amp;quot;Errore nell'apertura del file&amp;quot;); exit(1);}		&lt;br /&gt;
		while (n != 0) {&lt;br /&gt;
			n--;&lt;br /&gt;
			res = fgets(line, BUF_LEN, fd);&lt;br /&gt;
			if (res == NULL) {perror(&amp;quot;Errore nella fgets&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
		printf(&amp;quot;La riga richiesta del file %s ha %d caratteri.\n&amp;quot;, path, (int) strlen(line)-1 );&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
	int n;&lt;br /&gt;
	char path[PATH_LEN];&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	if (argc != 3) {printf(&amp;quot;Inserisci due parametri\n&amp;quot;); exit(1);}&lt;br /&gt;
	strcpy(path, argv[1]);&lt;br /&gt;
	n = atoi(argv[2]);&lt;br /&gt;
	lstat (path, &amp;amp;buf);&lt;br /&gt;
	if (S_ISREG(buf.st_mode) != 0) printLine(path, n);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[Esercizio 2]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define PATH_LEN 100&lt;br /&gt;
#define BUF_LEN 200&lt;br /&gt;
&lt;br /&gt;
int printLine(char *path, int n){&lt;br /&gt;
		FILE* fd;&lt;br /&gt;
		char line[BUF_LEN];&lt;br /&gt;
		char* res;&lt;br /&gt;
		fd = fopen(path, &amp;quot;r&amp;quot;);&lt;br /&gt;
		if (fd == NULL) {perror(&amp;quot;Errore nell'apertura del file&amp;quot;); exit(1);}		&lt;br /&gt;
		while (n != 0) {&lt;br /&gt;
			n--;&lt;br /&gt;
			res = fgets(line, BUF_LEN, fd);&lt;br /&gt;
			if (res == NULL) {perror(&amp;quot;Errore nella fgets&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
		printf(&amp;quot;La riga richiesta del file %s ha %d caratteri.\n&amp;quot;, path, (int) strlen(line)-1 );&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
		return ((int) strlen(line)-1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
lineandir (char path[PATH_LEN], int line_num){&lt;br /&gt;
	int i, ris, counter;&lt;br /&gt;
	char nome[PATH_LEN];&lt;br /&gt;
	struct dirent **namelist;&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	strcpy (nome, path);&lt;br /&gt;
	counter = 0;&lt;br /&gt;
&lt;br /&gt;
	ris = scandir(path, &amp;amp;namelist, 0, alphasort);&lt;br /&gt;
	if (ris &amp;lt; 0) {perror(&amp;quot;scandir error:&amp;quot;); exit(1);}&lt;br /&gt;
	else {&lt;br /&gt;
		for(i=0; i&amp;lt;ris; i++){&lt;br /&gt;
			if ( strncmp(namelist[i]-&amp;gt;d_name, &amp;quot;.&amp;quot;, 1) == 0) continue;&lt;br /&gt;
			strcat(nome, namelist[i]-&amp;gt;d_name);&lt;br /&gt;
			lstat (nome, &amp;amp;buf);&lt;br /&gt;
			/*se l'iesimo file è regolare, conto i caratteri*/&lt;br /&gt;
			if (S_ISREG(buf.st_mode) != 0) counter += printLine(nome, line_num);&lt;br /&gt;
			/*rimetto la radice del nome a &amp;quot;./&amp;quot;*/&lt;br /&gt;
			strcpy (nome, path);		&lt;br /&gt;
		}&lt;br /&gt;
		printf(&amp;quot;la somma delle righe %d è %d\n&amp;quot;, line_num, counter);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
	int n;&lt;br /&gt;
	if (argc != 2) {printf(&amp;quot;Inserisci un parametro\n&amp;quot;); exit(1);}&lt;br /&gt;
	n = atoi(argv[1]);&lt;br /&gt;
	lineandir(&amp;quot;./&amp;quot;, n);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Coci&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2014.01.23&amp;diff=705</id>
		<title>ProvaPratica 2014.01.23</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=ProvaPratica_2014.01.23&amp;diff=705"/>
		<updated>2014-05-10T08:56:54Z</updated>

		<summary type="html">&lt;p&gt;Coci: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[C esercizi 1 e 2]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
*Esercizio 1: Linguaggio C (obbligatorio): (20 punti)&lt;br /&gt;
*Scrivere un programma in C “linean” che prenda come parametro il pathname di un file e un numero intero (che chiameremo n). &lt;br /&gt;
*Il programma deve stampare come output il numero di caratteri presenti nella n-ma riga del file se il file e' un file regolare di testo, non deve stampare nulla negli altri casi.&lt;br /&gt;
*Un file viene considerato di testo se tutti i suoi byte hanno valori compresi nel range 1-127.&lt;br /&gt;
*Per controllare se il file e' “regolare” usare la system call lstat&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 200&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd ){                                   //check if the file is a regular file of text,it means that every byte has a value between 1-127&lt;br /&gt;
	int c;&lt;br /&gt;
	while ( (c = getc ( fd ) ) != EOF &amp;amp;&amp;amp; c &amp;lt;= 127 );&lt;br /&gt;
	rewind(fd);                                           //sets the file's cursor at the beginning,otherwise the linean program cannot find the line&lt;br /&gt;
	return ( (c == EOF)? 1 : 0 );&lt;br /&gt;
}&lt;br /&gt;
	 &lt;br /&gt;
		&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void linean( char *path , int line ){&lt;br /&gt;
	FILE *fd;&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	char bufline[BUFFSIZE];&lt;br /&gt;
	char *res;&lt;br /&gt;
	int n = line;&lt;br /&gt;
	res = NULL;&lt;br /&gt;
	lstat( path , &amp;amp;buf );&lt;br /&gt;
	if ( S_ISREG( buf.st_mode ) )&lt;br /&gt;
	{&lt;br /&gt;
		fd = fopen( path , &amp;quot;r&amp;quot; );&lt;br /&gt;
		if ( fd == NULL )&lt;br /&gt;
		{&lt;br /&gt;
			perror( &amp;quot;Error to open the file\n&amp;quot; );&lt;br /&gt;
			exit(1);&lt;br /&gt;
		}&lt;br /&gt;
			if ( istextfile( fd ) )&lt;br /&gt;
			{&lt;br /&gt;
				while ( ( line &amp;gt; 0 ) )                                        //iterates until at the nline and when is reached then checks if the buffer contains something&lt;br /&gt;
				{&lt;br /&gt;
					res = fgets(bufline, BUFFSIZE , fd );    //every time the nline is buffered,when exits from the cicle, the buffer contains the nline &lt;br /&gt;
					line--;&lt;br /&gt;
				}&lt;br /&gt;
				if ( res != NULL )                &lt;br /&gt;
				{&lt;br /&gt;
					printf( &amp;quot;The file %s in line %d has : %d char\n&amp;quot; , path , n , ( strlen( bufline ) - 1 )  );  //strlen also consider the carriage return&lt;br /&gt;
				}&lt;br /&gt;
				else&lt;br /&gt;
				printf( &amp;quot;Error: isn't possible to find the line\n&amp;quot; );&lt;br /&gt;
			}&lt;br /&gt;
			else&lt;br /&gt;
				printf( &amp;quot;Error is not a regular file of text\n&amp;quot; );&lt;br /&gt;
				&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
				&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
		printf( &amp;quot;The file %s isn't a regular file\n&amp;quot; , path );&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
int main( int argc , char *argv[] ){&lt;br /&gt;
	int n = atoi( argv[2] );&lt;br /&gt;
	linean( argv[1] , n );&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
	&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
*Esercizio 2: completamento (10 punti)&lt;br /&gt;
*Si scriva un programma C chiamato “lineandir”. Il risultato del programma, stampato su standard output, deve essere un solo&lt;br /&gt;
*numero intero: la somma del numero di caratteri presenti nelle n-me righe di tutti i file regolari, di testo, non nascosti (il primo&lt;br /&gt;
*carattere deve essere diverso da punto) della directory corrente. &lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;dirent.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#define BUFFSIZE 200&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd );&lt;br /&gt;
int linean( char *path , int line );&lt;br /&gt;
void lineandir( char *dir , int line );&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void lineandir( char *dir , int line ){&lt;br /&gt;
	int count , i;&lt;br /&gt;
	int sumline;&lt;br /&gt;
	struct dirent **de;&lt;br /&gt;
	sumline = 0;&lt;br /&gt;
	count = scandir( dir , &amp;amp;de , NULL , alphasort );&lt;br /&gt;
	for ( i = 0 ; i &amp;lt; count ; i++ )&lt;br /&gt;
	{&lt;br /&gt;
		if ( de[i]-&amp;gt;d_name[0] != '.' )     //doesn't consider the hidden files&lt;br /&gt;
			sumline = sumline + linean( de[i]-&amp;gt;d_name , line );&lt;br /&gt;
		free(de[i]);&lt;br /&gt;
	}&lt;br /&gt;
	printf(&amp;quot;The sum of char for every regular text file's nline in the current directory is: %d\n&amp;quot; , sumline );&lt;br /&gt;
	free(de);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int istextfile( FILE *fd ){                                  &lt;br /&gt;
	int c;&lt;br /&gt;
	while ( (c = getc ( fd ) ) != EOF &amp;amp;&amp;amp; c &amp;lt;= 127 );&lt;br /&gt;
	rewind(fd);                                           &lt;br /&gt;
	return ( (c == EOF)? 1 : 0 );&lt;br /&gt;
}&lt;br /&gt;
	 &lt;br /&gt;
		&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*linean is modified so it can return the value of the char in the nline */&lt;br /&gt;
int linean( char *path , int line ){&lt;br /&gt;
	FILE *fd;&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	char bufline[BUFFSIZE];&lt;br /&gt;
	char *res;&lt;br /&gt;
	int n = line;&lt;br /&gt;
	res = NULL;&lt;br /&gt;
	lstat( path , &amp;amp;buf );&lt;br /&gt;
	if ( S_ISREG( buf.st_mode ) )&lt;br /&gt;
	{&lt;br /&gt;
		fd = fopen( path , &amp;quot;r&amp;quot; );&lt;br /&gt;
		if ( fd == NULL )&lt;br /&gt;
		{&lt;br /&gt;
			perror( &amp;quot;Error to open the file\n&amp;quot; );&lt;br /&gt;
			exit(1);&lt;br /&gt;
		}&lt;br /&gt;
			if ( istextfile( fd ) )&lt;br /&gt;
			{&lt;br /&gt;
				while ( ( line &amp;gt; 0 ) )                                        &lt;br /&gt;
				{&lt;br /&gt;
					res = fgets(bufline, BUFFSIZE , fd );    &lt;br /&gt;
					line--;&lt;br /&gt;
				}&lt;br /&gt;
				if ( res != NULL )                &lt;br /&gt;
				{&lt;br /&gt;
					return( ( strlen( bufline ) - 1 )  );  &lt;br /&gt;
				}&lt;br /&gt;
				else&lt;br /&gt;
				printf( &amp;quot;Error: isn't possible to find the line\n&amp;quot; );&lt;br /&gt;
			}&lt;br /&gt;
			else&lt;br /&gt;
				printf( &amp;quot;Error is not a regular file of text\n&amp;quot; );&lt;br /&gt;
				&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
				&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
		printf( &amp;quot;The file %s isn't a regular file\n&amp;quot; , path );&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
int main( int argc , char *argv[] ){&lt;br /&gt;
	int n = atoi( argv[1] );&lt;br /&gt;
	lineandir( &amp;quot;./&amp;quot; , n );&lt;br /&gt;
	return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[Bash esercizio 3]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
#Il comando che dovrete implementare come script shell o programma python e' updatedir. Updatedir prende due directorycome parametri.&lt;br /&gt;
#updatedir dira dirb deve copiare in dirb tutti i file regolari che sono in dira e non in dirb. Se un file regolare e' presente con lo stesso nome sia in&lt;br /&gt;
#dira sia in dirb, il file deve essere copiato dalla dira alla dirb solo se i contenuti differiscono.&lt;br /&gt;
&lt;br /&gt;
#! /bin/bash&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for file in &amp;quot;$1&amp;quot;/*; do&lt;br /&gt;
	if [[ -f $file ]] ; then          #checks if the file is regular&lt;br /&gt;
		thereisnotfile=1          #variable that identify if the file is also in dir2&lt;br /&gt;
		for file2 in &amp;quot;$2&amp;quot;/*; do&lt;br /&gt;
			if [[ -f $file2 ]] ; then&lt;br /&gt;
				if [[  $file2 !=  $file ]] ; then      #checks if the file is only in dir1 and not in dir2&lt;br /&gt;
					continue&lt;br /&gt;
				else&lt;br /&gt;
					thereisnotfile=0            #the file is in both dir&lt;br /&gt;
				fi&lt;br /&gt;
				if [[ $thereisnotfile -eq 0 ]]; then      &lt;br /&gt;
					if [[ $(md5sum &amp;quot;$file&amp;quot;) != $(md5sum &amp;quot;$file2&amp;quot;) ]] ; then   #checks if the file in dir1 is different of file in dir2 by md5sum &lt;br /&gt;
						bn=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
						cp $file  &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
						thereisnotfile=2        #is set in this way for not continue to iterate&lt;br /&gt;
					fi&lt;br /&gt;
				fi&lt;br /&gt;
			fi&lt;br /&gt;
		done&lt;br /&gt;
		if [[ $thereisnotfile -eq 1 ]]; then&lt;br /&gt;
			bn=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
			cp $file  &amp;quot;$2&amp;quot;/&amp;quot;$bn&amp;quot;&lt;br /&gt;
		fi&lt;br /&gt;
	fi&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;		&lt;br /&gt;
Pirata&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
function usage {&lt;br /&gt;
  command=$(basename &amp;quot;$0&amp;quot;)&lt;br /&gt;
  echo &amp;quot;Usage: $command source destination&amp;quot;&lt;br /&gt;
  exit 1&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if [[ ! -d $1 ]]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;Source is not a dir&amp;quot;&lt;br /&gt;
  usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [[ ! -d $2 ]]&lt;br /&gt;
then&lt;br /&gt;
  echo &amp;quot;Destination is not a dir&amp;quot;&lt;br /&gt;
  usage&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
find $1 -type f -print0 | while IFS= read -r -d $'\0' file; do&lt;br /&gt;
  filename=$(basename &amp;quot;$file&amp;quot;)&lt;br /&gt;
  if [[ -f &amp;quot;$2$filename&amp;quot; ]]&lt;br /&gt;
  then&lt;br /&gt;
  	  cp &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  else&lt;br /&gt;
  	  if cmp -s &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  	  then&lt;br /&gt;
  	  	  /* Do nothing are the same */&lt;br /&gt;
  	  else&lt;br /&gt;
  	  	  cp &amp;quot;$file&amp;quot; &amp;quot;$2$filename&amp;quot;&lt;br /&gt;
  	  fi&lt;br /&gt;
  fi	  &lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Mrta&lt;br /&gt;
&lt;br /&gt;
[Esercizio 1]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#define PATH_LEN 100&lt;br /&gt;
#define BUF_LEN 200&lt;br /&gt;
&lt;br /&gt;
printLine(char *path, int n){&lt;br /&gt;
		FILE* fd;&lt;br /&gt;
		char line[BUF_LEN];&lt;br /&gt;
		char* res;&lt;br /&gt;
		fd = fopen(path, &amp;quot;r&amp;quot;);&lt;br /&gt;
		if (fd == NULL) {perror(&amp;quot;Errore nell'apertura del file&amp;quot;); exit(1);}		&lt;br /&gt;
		while (n != 0) {&lt;br /&gt;
			n--;&lt;br /&gt;
			res = fgets(line, BUF_LEN, fd);&lt;br /&gt;
			if (res == NULL) {perror(&amp;quot;Errore nella fgets&amp;quot;); exit(1);}&lt;br /&gt;
		}&lt;br /&gt;
		printf(&amp;quot;La riga richiesta del file %s ha %d caratteri.\n&amp;quot;, path, (int) strlen(line)-1 );&lt;br /&gt;
		fclose(fd);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char* argv[]){&lt;br /&gt;
	int n;&lt;br /&gt;
	char path[PATH_LEN];&lt;br /&gt;
	struct stat buf;&lt;br /&gt;
	if (argc != 3) {printf(&amp;quot;Inserisci due parametri\n&amp;quot;); exit(1);}&lt;br /&gt;
	strcpy(path, argv[1]);&lt;br /&gt;
	n = atoi(argv[2]);&lt;br /&gt;
	lstat (path, &amp;amp;buf);&lt;br /&gt;
	if (S_ISREG(buf.st_mode) != 0) printLine(path, n);&lt;br /&gt;
	return 1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Coci&lt;/div&gt;</summary>
		<author><name>Coci</name></author>
	</entry>
</feed>