<?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=LeonardoF</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=LeonardoF"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php/Special:Contributions/LeonardoF"/>
	<updated>2026-05-03T13:33:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=User:LeonardoF&amp;diff=1893</id>
		<title>User:LeonardoF</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=User:LeonardoF&amp;diff=1893"/>
		<updated>2017-05-26T08:53:44Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1783</id>
		<title>Prova pratica 2014.09.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1783"/>
		<updated>2017-04-30T16:53:42Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2014.09.25.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot;  //https://github.com/rd235/s2argv-execs&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define AOI_LENSTEP 8&lt;br /&gt;
#define BUFFLEN  256&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
struct array_of_integers {&lt;br /&gt;
    int **integers;&lt;br /&gt;
    size_t currentlength; //the length of number of integers in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_integers array_of_integers;&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_add(array_of_integers *arrayOfIntegers, int val) {&lt;br /&gt;
   &lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;gt;= arrayOfIntegers-&amp;gt;arraylength) {&lt;br /&gt;
        size_t newlength = arrayOfIntegers-&amp;gt;arraylength + AOI_LENSTEP;&lt;br /&gt;
         int **new_vec = realloc(arrayOfIntegers-&amp;gt;integers, newlength * sizeof(arrayOfIntegers-&amp;gt;integers[0]));&lt;br /&gt;
&lt;br /&gt;
        if (new_vec != NULL) {&lt;br /&gt;
            arrayOfIntegers-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfIntegers-&amp;gt;integers = new_vec;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;lt; arrayOfIntegers-&amp;gt;arraylength)  &lt;br /&gt;
        arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength] = malloc(sizeof(int));&lt;br /&gt;
        *(arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength++]) = val;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_print(array_of_integers *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %d\n&amp;quot;, i, *(v-&amp;gt;integers[i]));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	/*opening and reading the file*/&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
	ssize_t numberOfCharactersRead;&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
    FILE* fd1 = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    static array_of_integers arrayOfPid;&lt;br /&gt;
    static array_of_integers arrayOfFd;&lt;br /&gt;
    int fd; //file descriptor&lt;br /&gt;
    int i = 0; //iterator&lt;br /&gt;
    char concat[BUFFLEN];&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd1)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
       &lt;br /&gt;
 	///&lt;br /&gt;
 	/*done*/&lt;br /&gt;
 	/* opening output files, forking , saving pids and file descriptors*/&lt;br /&gt;
    sprintf(concat,&amp;quot;./temp%d&amp;quot;,i);&lt;br /&gt;
    fd = open(concat,O_RDWR | O_CREAT | O_TRUNC , 0666);&lt;br /&gt;
&lt;br /&gt;
 	int pid = fork();&lt;br /&gt;
 	switch(pid){&lt;br /&gt;
 		case 0: //children&lt;br /&gt;
                        //children stdio = file fd&lt;br /&gt;
                        dup2(fd,STDOUT_FILENO);&lt;br /&gt;
			//execution of the command&lt;br /&gt;
			execsp(line);&lt;br /&gt;
 		        exit(-1); // in case of execsp failure&lt;br /&gt;
 		default: //parent &lt;br /&gt;
                         //must save all the pids&lt;br /&gt;
                         array_of_integers_add(&amp;amp;arrayOfPid,pid);&lt;br /&gt;
                         //must save all the fds. ( they will have the same order of the pids);&lt;br /&gt;
                         array_of_integers_add(&amp;amp;arrayOfFd,fd); &lt;br /&gt;
 			&lt;br /&gt;
                         i ++;&lt;br /&gt;
 			 break;&lt;br /&gt;
 			}&lt;br /&gt;
 		&lt;br /&gt;
 	}&lt;br /&gt;
    free(line);&lt;br /&gt;
    /*done*/&lt;br /&gt;
    &lt;br /&gt;
    /*waiting first process and killing the others*/&lt;br /&gt;
    int firstpid;&lt;br /&gt;
    size_t j; //iterator&lt;br /&gt;
    size_t firstpid_pos; //position of the first pid in the array&lt;br /&gt;
    //wait the first process&lt;br /&gt;
    firstpid = wait(NULL);&lt;br /&gt;
 &lt;br /&gt;
    /*sigterm the other processes iterating the pids vector*/&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfPid)-&amp;gt;currentlength; j++){&lt;br /&gt;
        int temp = *((&amp;amp;arrayOfPid)-&amp;gt;integers[j]);&lt;br /&gt;
&lt;br /&gt;
        if(temp != firstpid)&lt;br /&gt;
            kill( temp,SIGTERM);&lt;br /&gt;
        else &lt;br /&gt;
        	firstpid_pos = j ;&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    /*printing the file of the &amp;quot;fisrt pid&amp;quot; process , unlinking the file and closing them*/&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfFd)-&amp;gt;currentlength; j++){&lt;br /&gt;
    	 fd = *((&amp;amp;arrayOfFd)-&amp;gt;integers[j]);&lt;br /&gt;
    &lt;br /&gt;
    	sprintf(concat,&amp;quot;./temp%lu&amp;quot;,j);&lt;br /&gt;
&lt;br /&gt;
    	if (j == firstpid_pos){&lt;br /&gt;
    		int c;&lt;br /&gt;
    		//lseek is needed because the file is inherited&lt;br /&gt;
    		lseek(fd,0,SEEK_SET);&lt;br /&gt;
    		&lt;br /&gt;
    		FILE *fdp = fdopen(fd,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		while ((c = getc(fdp)) != EOF)&lt;br /&gt;
        		putchar(c);&lt;br /&gt;
    	}   	&lt;br /&gt;
    	//unlink file fd&lt;br /&gt;
    	unlink(concat);&lt;br /&gt;
    	//close file fd&lt;br /&gt;
    	close(fd);&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 11:33, 26 April 2017 (CEST)LeonardoF&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1782</id>
		<title>Prova pratica 2015.01.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1782"/>
		<updated>2017-04-29T22:45:01Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2015.01.21.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 1&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot; // from https://github.com/rd235/s2argv-execs&lt;br /&gt;
#define BUFFLEN  4096 //probably there is a system constant&lt;br /&gt;
&lt;br /&gt;
int main(int argc,const char* argv[]){&lt;br /&gt;
	//take the path name and open the file&lt;br /&gt;
	FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	//read the the file and put its content in a array of pointers&lt;br /&gt;
	char commands[2][BUFFLEN]; //migliorabile&lt;br /&gt;
	char buffer[BUFFLEN];&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (fgets(buffer,sizeof(buffer),fd) != NULL){&lt;br /&gt;
		strcpy(commands[i],buffer);&lt;br /&gt;
		i ++;&lt;br /&gt;
	}&lt;br /&gt;
	//printf(&amp;quot;%s\n%s\n&amp;quot;,commands[0],commands[1] );&lt;br /&gt;
	//create a pipe&lt;br /&gt;
	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	//fork&lt;br /&gt;
	int pid;&lt;br /&gt;
	pid = fork();&lt;br /&gt;
	switch (pid){&lt;br /&gt;
	case 0 : //children&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//children's stout = pipe output&lt;br /&gt;
		dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//execution of the command&lt;br /&gt;
		execsp(commands[0]);&lt;br /&gt;
		&lt;br /&gt;
		exit(-1); // in case of execsp failure&lt;br /&gt;
&lt;br /&gt;
	default : //parent&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//father's stdin = pipe input&lt;br /&gt;
		dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//receive the comnmand&lt;br /&gt;
		execsp(commands[1]);&lt;br /&gt;
		&lt;br /&gt;
		exit(-1);&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot; // from https://github.com/rd235/s2argv-execs&lt;br /&gt;
 &lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
&lt;br /&gt;
    ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	//array_of_strings_print(&amp;amp;arrayOfStrings);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,commandNumber );&lt;br /&gt;
 	//open the pipe&lt;br /&gt;
 	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	int i = 0;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
 		if(commandNumber &amp;gt; 1) {&lt;br /&gt;
 			int pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
 						close(fpipe[0]);&lt;br /&gt;
						//children's stout = pipe output&lt;br /&gt;
						dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
						close(fpipe[1]);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
						//usleep( commandNumber* 1000000);&lt;br /&gt;
						execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
						&lt;br /&gt;
 						exit(-1);&lt;br /&gt;
 				default: //parent &lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		}&lt;br /&gt;
 		else{ //last command&lt;br /&gt;
 				close(fpipe[1]);&lt;br /&gt;
				//father's stdin = pipe input&lt;br /&gt;
				dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
				close(fpipe[0]);&lt;br /&gt;
				//receive the comnmand&lt;br /&gt;
				execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Bash&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;
#ESERCIZIO 3&lt;br /&gt;
&lt;br /&gt;
find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
shift &lt;br /&gt;
&lt;br /&gt;
for i in $@ ; do&lt;br /&gt;
	find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
	shift&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
#ESERCIZIO 3&lt;br /&gt;
import sys&lt;br /&gt;
# os.syscall way to use linux syscalls&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
dictionary = {}&lt;br /&gt;
&lt;br /&gt;
def add(md5val,path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that insert the given file path in a dictionary&lt;br /&gt;
	using as key the given md5sum&amp;quot;&amp;quot;&amp;quot;	&lt;br /&gt;
	#in this way i avoid duplicates&lt;br /&gt;
	dictionary.setdefault(md5val,set()).add(path)&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def md5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that takes a filepath and calculate is md5sum&lt;br /&gt;
	then it calls a function to insert the file in a dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	md5val = hashlib.md5()&lt;br /&gt;
	with open(path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
		#Note that sometimes you won't be able to fit the whole file in memory. &lt;br /&gt;
		#In that case, you'll have to read chunks of 4096 bytes sequentially and feed them to the Md5 function:&lt;br /&gt;
		for chunk in iter(lambda: f.read(4096), b&amp;quot;&amp;quot;):&lt;br /&gt;
			md5val.update(chunk)&lt;br /&gt;
	add(md5val.hexdigest(),path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def movmd5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;recursive fuction that moves in the file system and call the mdadd function&lt;br /&gt;
	it takes a path in input (main checks the path given by the user) &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for root, dirs, files in os.walk(path):&lt;br /&gt;
		for f in files:&lt;br /&gt;
			#if file call the function for the md5sum &lt;br /&gt;
			md5add(os.path.join(root,f)) # os.path.join(root,f)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def printdict():&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;funtion that prints the dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for x in dictionary:&lt;br /&gt;
		#doesn't print single lines&lt;br /&gt;
		if len(dictionary[x]) &amp;gt; 1 :&lt;br /&gt;
			print('\r')&lt;br /&gt;
			for y in dictionary[x]:&lt;br /&gt;
				print(x,&amp;quot; : &amp;quot;,y)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;main checks the path and call the functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if len(args) &amp;lt; 1:&lt;br /&gt;
		args = &amp;quot;.&amp;quot;&lt;br /&gt;
	for path in args:&lt;br /&gt;
		movmd5add(path)&lt;br /&gt;
	printdict()&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
		main(sys.argv[1:])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
Scrivere un programma python o uno script bash che scandisca il sottoalbero relativo alle directory passate come&lt;br /&gt;
parametri (o alla direcotry corrente se non ci sono parametri) e fornisca in output l'elenco dei file che hanno la&lt;br /&gt;
stessa somma MD5 (i.e. l'output del comando md5sum).&lt;br /&gt;
In output ogni riga deve mostrare un elenco di pathname realtivi a file che hanno la stessa somma MD5 (che quindi&lt;br /&gt;
sono molto molto probabilmente uguali).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
def sha1sum(root, filename):&lt;br /&gt;
    sha1 = hashlib.sha1()&lt;br /&gt;
    with open(os.path.join(root, filename), &amp;quot;rb&amp;quot;) as thefile:&lt;br /&gt;
        buf = thefile.read()&lt;br /&gt;
        sha1.update(buf)&lt;br /&gt;
    return sha1.hexdigest()&lt;br /&gt;
&lt;br /&gt;
def initSha1vect(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Inizializza il dizionario utilizzando come chiave il sha1&lt;br /&gt;
    del file, e come valore il percorso del file. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    shafiles = {}&lt;br /&gt;
    for root, dirs, files in os.walk(path):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            shaKey = sha1sum(root, file)&lt;br /&gt;
            shafiles.setdefault(shaKey, [])&lt;br /&gt;
            shafiles[shaKey].append(file)&lt;br /&gt;
    return shafiles&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
    for path in args:&lt;br /&gt;
        msg = True&lt;br /&gt;
        print &amp;quot;\n&amp;quot;, path&lt;br /&gt;
        shafiles = initSha1vect(path)&lt;br /&gt;
        for k in shafiles:&lt;br /&gt;
            if len(shafiles[k]) &amp;gt; 1:&lt;br /&gt;
                msg = False&lt;br /&gt;
                print k, &amp;quot;\t&amp;quot;, shafiles[k]&lt;br /&gt;
        if msg:&lt;br /&gt;
            print &amp;quot;Nessun file con lo stesso sha1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
	main(sys.argv[1:])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:S.G|S.G]] ([[User talk:S.G|talk]]) 14:39, 18 November 2016 (CET)&amp;lt;br&amp;gt;&lt;br /&gt;
Ho scritto una possibile soluzione dell'esercizio 3&lt;br /&gt;
&lt;br /&gt;
'''perch&amp;amp;eacute; proporre una soluzione in un linguaggio che non ho ancora spiegato?'''[[User:Renzo|Renzo]] ([[User talk:Renzo|talk]]) 19:36, 21 November 2016 (CET)&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1781</id>
		<title>Prova pratica 2014.09.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1781"/>
		<updated>2017-04-29T16:34:18Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2014.09.25.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot;  //https://github.com/rd235/s2argv-execs&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define AOI_LENSTEP 8&lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
#define BUFFLEN  256&lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//readapting the struct and the functions above to manage integers&lt;br /&gt;
//polymorphism?&lt;br /&gt;
struct array_of_integers {&lt;br /&gt;
    int **integers;&lt;br /&gt;
    size_t currentlength; //the length of number of integers in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_integers array_of_integers;&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_add(array_of_integers *arrayOfIntegers, int val) {&lt;br /&gt;
   &lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;gt;= arrayOfIntegers-&amp;gt;arraylength) {&lt;br /&gt;
        size_t newlength = arrayOfIntegers-&amp;gt;arraylength + AOI_LENSTEP;&lt;br /&gt;
         int **new_vec = realloc(arrayOfIntegers-&amp;gt;integers, newlength * sizeof(arrayOfIntegers-&amp;gt;integers[0]));&lt;br /&gt;
&lt;br /&gt;
        if (new_vec != NULL) {&lt;br /&gt;
            arrayOfIntegers-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfIntegers-&amp;gt;integers = new_vec;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;lt; arrayOfIntegers-&amp;gt;arraylength)  &lt;br /&gt;
        arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength] = malloc(sizeof(int));&lt;br /&gt;
        *(arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength++]) = val;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_print(array_of_integers *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %d\n&amp;quot;, i, *(v-&amp;gt;integers[i]));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	/*opening and reading the file*/&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
	ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    &lt;br /&gt;
    FILE* fd1 = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd1)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	/*done*/&lt;br /&gt;
 	/* opening output files, forking , saving pids and file descriptors*/&lt;br /&gt;
 	int pid;&lt;br /&gt;
	int i = 0; //iterator&lt;br /&gt;
	int fd; //file descriptor&lt;br /&gt;
	char concat[BUFFLEN];&lt;br /&gt;
    static array_of_integers arrayOfPid;&lt;br /&gt;
    static array_of_integers arrayOfFd;&lt;br /&gt;
    &lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
            sprintf(concat,&amp;quot;./temp%d&amp;quot;,i);&lt;br /&gt;
            fd = open(concat,O_RDWR | O_CREAT | O_TRUNC , 0666);&lt;br /&gt;
&lt;br /&gt;
 			pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
                                        //children stdio = file fd&lt;br /&gt;
                                        dup2(fd,STDOUT_FILENO);&lt;br /&gt;
				        //execution of the command&lt;br /&gt;
				        execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
 				        exit(-1); // in case of execsp failure&lt;br /&gt;
 				default: //parent &lt;br /&gt;
                                         //must save all the pids&lt;br /&gt;
                                         array_of_integers_add(&amp;amp;arrayOfPid,pid);&lt;br /&gt;
                                         //must save all the fds. ( they will have the same order of the pids);&lt;br /&gt;
                                          array_of_integers_add(&amp;amp;arrayOfFd,fd); &lt;br /&gt;
 					  commandNumber --;&lt;br /&gt;
 					  i ++;&lt;br /&gt;
 					  break;&lt;br /&gt;
 			}&lt;br /&gt;
 		&lt;br /&gt;
 	}&lt;br /&gt;
    printf(&amp;quot;arrayofFd\n&amp;quot;);&lt;br /&gt;
    array_of_integers_print(&amp;amp;arrayOfFd);&lt;br /&gt;
    /*done*/&lt;br /&gt;
    /*waiting first process and killing the others*/&lt;br /&gt;
 	int firstpid;&lt;br /&gt;
 	size_t j; //iterator&lt;br /&gt;
    size_t firstpid_pos; //position of the first pid in the array&lt;br /&gt;
    //wait the first process&lt;br /&gt;
 	firstpid = wait(NULL);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,firstpid );&lt;br /&gt;
    //sigterm the other processes iterating the pids vector&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfPid)-&amp;gt;currentlength; j++){&lt;br /&gt;
        int temp = *((&amp;amp;arrayOfPid)-&amp;gt;integers[j]);&lt;br /&gt;
&lt;br /&gt;
        if(temp != firstpid)&lt;br /&gt;
            kill( temp,SIGTERM);&lt;br /&gt;
        else &lt;br /&gt;
        	firstpid_pos = j ;&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
    /*printign the file of the &amp;quot;fisrt pid&amp;quot; process , unlinking the file and closing them*/&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfFd)-&amp;gt;currentlength; j++){&lt;br /&gt;
    	 fd = *((&amp;amp;arrayOfFd)-&amp;gt;integers[j]);&lt;br /&gt;
    &lt;br /&gt;
    	sprintf(concat,&amp;quot;./temp%lu&amp;quot;,j);&lt;br /&gt;
    	if (j == firstpid_pos){&lt;br /&gt;
    		int c;&lt;br /&gt;
    		//lseek is needed because the file is inherited&lt;br /&gt;
    		lseek(fd,0,SEEK_SET);&lt;br /&gt;
    		&lt;br /&gt;
    		FILE *fdp = fdopen(fd,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		&lt;br /&gt;
&lt;br /&gt;
    		   while ((c = getc(fdp)) != EOF)&lt;br /&gt;
        			putchar(c);&lt;br /&gt;
   &lt;br /&gt;
    		&lt;br /&gt;
&lt;br /&gt;
    	}&lt;br /&gt;
    	&lt;br /&gt;
    	//unlink file fd&lt;br /&gt;
    	unlink(concat);&lt;br /&gt;
    	//close file fd&lt;br /&gt;
    	close(fd);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 11:33, 26 April 2017 (CEST)LeonardoF&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1778</id>
		<title>Prova pratica 2014.09.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1778"/>
		<updated>2017-04-26T09:35:11Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2014.09.25.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot;  //https://github.com/rd235/s2argv-execs&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define AOI_LENSTEP 8&lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
#define BUFFLEN  256&lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//readapting the struct and the functions above to manage integers&lt;br /&gt;
//polymorphism?&lt;br /&gt;
struct array_of_integers {&lt;br /&gt;
    int **integers;&lt;br /&gt;
    size_t currentlength; //the length of number of integers in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_integers array_of_integers;&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_add(array_of_integers *arrayOfIntegers, int val) {&lt;br /&gt;
   &lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;gt;= arrayOfIntegers-&amp;gt;arraylength) {&lt;br /&gt;
        size_t newlength = arrayOfIntegers-&amp;gt;arraylength + AOI_LENSTEP;&lt;br /&gt;
         int **new_vec = realloc(arrayOfIntegers-&amp;gt;integers, newlength * sizeof(arrayOfIntegers-&amp;gt;integers[0]));&lt;br /&gt;
&lt;br /&gt;
        if (new_vec != NULL) {&lt;br /&gt;
            arrayOfIntegers-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfIntegers-&amp;gt;integers = new_vec;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;lt; arrayOfIntegers-&amp;gt;arraylength)  &lt;br /&gt;
        arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength] = malloc(sizeof(int));&lt;br /&gt;
        *(arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength++]) = val;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_print(array_of_integers *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %d\n&amp;quot;, i, *(v-&amp;gt;integers[i]));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	/*opening and reading the file*/&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
	ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    &lt;br /&gt;
    FILE* fd1 = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd1)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	/*done*/&lt;br /&gt;
 	/* opening output files, forking , saving pids and file descriptors*/&lt;br /&gt;
 	int pid;&lt;br /&gt;
	int i = 0; //iterator&lt;br /&gt;
	int fd; //file descriptor&lt;br /&gt;
	char concat[BUFFLEN];&lt;br /&gt;
    static array_of_integers arrayOfPid;&lt;br /&gt;
    static array_of_integers arrayOfFd;&lt;br /&gt;
    &lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
            sprintf(concat,&amp;quot;./temp%d&amp;quot;,i);&lt;br /&gt;
            fd = open(concat,O_RDWR | O_CREAT | O_TRUNC , 0666);&lt;br /&gt;
&lt;br /&gt;
 			pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
                        //children stdio = file fd&lt;br /&gt;
                        dup2(fd,STDOUT_FILENO);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
				        execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
                        //must save all the pids&lt;br /&gt;
                        array_of_integers_add(&amp;amp;arrayOfPid,pid);&lt;br /&gt;
                        //must save all the fds. ( they will have the same order of the pids);&lt;br /&gt;
                        array_of_integers_add(&amp;amp;arrayOfFd,fd); /*this statement needs to be discussed*/&lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		&lt;br /&gt;
 	}&lt;br /&gt;
    printf(&amp;quot;arrayofFd\n&amp;quot;);&lt;br /&gt;
    array_of_integers_print(&amp;amp;arrayOfFd);&lt;br /&gt;
    /*done*/&lt;br /&gt;
    /*waiting first process and killing the others*/&lt;br /&gt;
 	int firstpid;&lt;br /&gt;
 	size_t j; //iterator&lt;br /&gt;
    size_t firstpid_pos; //position of the first pid in the array&lt;br /&gt;
    //wait the first process&lt;br /&gt;
 	firstpid = wait(NULL);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,firstpid );&lt;br /&gt;
    //sigterm the other processes iterating the pids vector&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfPid)-&amp;gt;currentlength; j++){&lt;br /&gt;
        int temp = *((&amp;amp;arrayOfPid)-&amp;gt;integers[j]);&lt;br /&gt;
&lt;br /&gt;
        if(temp != firstpid)&lt;br /&gt;
            kill( temp,SIGTERM);&lt;br /&gt;
        else &lt;br /&gt;
        	firstpid_pos = j ;&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    /*this part needs to be discussed*/&lt;br /&gt;
    /*printign the file of the &amp;quot;fisrt pid&amp;quot; process , unlinking the file and closing them*/&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfFd)-&amp;gt;currentlength; j++){&lt;br /&gt;
    	 fd = *((&amp;amp;arrayOfFd)-&amp;gt;integers[j]);&lt;br /&gt;
    &lt;br /&gt;
    	sprintf(concat,&amp;quot;./temp%lu&amp;quot;,j);&lt;br /&gt;
    	if (j == firstpid_pos){&lt;br /&gt;
    		int c;&lt;br /&gt;
    		//FILE *fdp = fdopen(fd,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		FILE *fdp = fopen(concat,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		&lt;br /&gt;
    		   while ((c = getc(fdp)) != EOF)&lt;br /&gt;
        			putchar(c);&lt;br /&gt;
   &lt;br /&gt;
    		&lt;br /&gt;
&lt;br /&gt;
    	}&lt;br /&gt;
    	&lt;br /&gt;
    	//unlink file fd&lt;br /&gt;
    	unlink(concat);&lt;br /&gt;
    	//close file fd&lt;br /&gt;
    	close(fd);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 11:33, 26 April 2017 (CEST)LeonardoF&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1777</id>
		<title>Prova pratica 2014.09.25</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2014.09.25&amp;diff=1777"/>
		<updated>2017-04-26T09:33:56Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: Created page with &amp;quot;Testo: [http://http://www.cs.unibo.it/~renzo/so/pratiche/2014.09.25.pdf]  Esercizio 2  &amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt; //ESERCIZIO 2 #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://http://www.cs.unibo.it/~renzo/so/pratiche/2014.09.25.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 2&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot;  //https://github.com/rd235/s2argv-execs&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define AOI_LENSTEP 8&lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
#define BUFFLEN  256&lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//readapting the struct and the functions above to manage integers&lt;br /&gt;
//polymorphism?&lt;br /&gt;
struct array_of_integers {&lt;br /&gt;
    int **integers;&lt;br /&gt;
    size_t currentlength; //the length of number of integers in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_integers array_of_integers;&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_add(array_of_integers *arrayOfIntegers, int val) {&lt;br /&gt;
   &lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;gt;= arrayOfIntegers-&amp;gt;arraylength) {&lt;br /&gt;
        size_t newlength = arrayOfIntegers-&amp;gt;arraylength + AOI_LENSTEP;&lt;br /&gt;
         int **new_vec = realloc(arrayOfIntegers-&amp;gt;integers, newlength * sizeof(arrayOfIntegers-&amp;gt;integers[0]));&lt;br /&gt;
&lt;br /&gt;
        if (new_vec != NULL) {&lt;br /&gt;
            arrayOfIntegers-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfIntegers-&amp;gt;integers = new_vec;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    if (arrayOfIntegers-&amp;gt;currentlength &amp;lt; arrayOfIntegers-&amp;gt;arraylength)  &lt;br /&gt;
        arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength] = malloc(sizeof(int));&lt;br /&gt;
        *(arrayOfIntegers-&amp;gt;integers[arrayOfIntegers-&amp;gt;currentlength++]) = val;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_integers_print(array_of_integers *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %d\n&amp;quot;, i, *(v-&amp;gt;integers[i]));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	/*opening and reading the file*/&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
	ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    &lt;br /&gt;
    FILE* fd1 = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd1)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	/*done*/&lt;br /&gt;
 	/* opening output files, forking , saving pids and file descriptors*/&lt;br /&gt;
 	int pid;&lt;br /&gt;
	int i = 0; //iterator&lt;br /&gt;
	int fd; //file descriptor&lt;br /&gt;
	char concat[BUFFLEN];&lt;br /&gt;
    static array_of_integers arrayOfPid;&lt;br /&gt;
    static array_of_integers arrayOfFd;&lt;br /&gt;
    &lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
            sprintf(concat,&amp;quot;./temp%d&amp;quot;,i);&lt;br /&gt;
            fd = open(concat,O_RDWR | O_CREAT | O_TRUNC , 0666);&lt;br /&gt;
&lt;br /&gt;
 			pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
                        //children stdio = file fd&lt;br /&gt;
                        dup2(fd,STDOUT_FILENO);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
				        execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
                        //must save all the pids&lt;br /&gt;
                        array_of_integers_add(&amp;amp;arrayOfPid,pid);&lt;br /&gt;
                        //must save all the fds. ( they will have the same order of the pids);&lt;br /&gt;
                        array_of_integers_add(&amp;amp;arrayOfFd,fd); /*this statement needs to be discussed*/&lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		&lt;br /&gt;
 	}&lt;br /&gt;
    printf(&amp;quot;arrayofFd\n&amp;quot;);&lt;br /&gt;
    array_of_integers_print(&amp;amp;arrayOfFd);&lt;br /&gt;
    /*done*/&lt;br /&gt;
    /*waiting first process and killing the others*/&lt;br /&gt;
 	int firstpid;&lt;br /&gt;
 	size_t j; //iterator&lt;br /&gt;
    size_t firstpid_pos; //position of the first pid in the array&lt;br /&gt;
    //wait the first process&lt;br /&gt;
 	firstpid = wait(NULL);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,firstpid );&lt;br /&gt;
    //sigterm the other processes iterating the pids vector&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfPid)-&amp;gt;currentlength; j++){&lt;br /&gt;
        int temp = *((&amp;amp;arrayOfPid)-&amp;gt;integers[j]);&lt;br /&gt;
&lt;br /&gt;
        if(temp != firstpid)&lt;br /&gt;
            kill( temp,SIGTERM);&lt;br /&gt;
        else &lt;br /&gt;
        	firstpid_pos = j ;&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    /*this part needs to be discussed*/&lt;br /&gt;
    /*printign the file of the &amp;quot;fisrt pid&amp;quot; process , unlinking the file and closing them*/&lt;br /&gt;
    for (j = 0; j &amp;lt; (&amp;amp;arrayOfFd)-&amp;gt;currentlength; j++){&lt;br /&gt;
    	 fd = *((&amp;amp;arrayOfFd)-&amp;gt;integers[j]);&lt;br /&gt;
    &lt;br /&gt;
    	sprintf(concat,&amp;quot;./temp%lu&amp;quot;,j);&lt;br /&gt;
    	if (j == firstpid_pos){&lt;br /&gt;
    		int c;&lt;br /&gt;
    		//FILE *fdp = fdopen(fd,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		FILE *fdp = fopen(concat,&amp;quot;r&amp;quot;);&lt;br /&gt;
    		&lt;br /&gt;
    		   while ((c = getc(fdp)) != EOF)&lt;br /&gt;
        			putchar(c);&lt;br /&gt;
   &lt;br /&gt;
    		&lt;br /&gt;
&lt;br /&gt;
    	}&lt;br /&gt;
    	&lt;br /&gt;
    	//unlink file fd&lt;br /&gt;
    	unlink(concat);&lt;br /&gt;
    	//close file fd&lt;br /&gt;
    	close(fd);&lt;br /&gt;
&lt;br /&gt;
    }&lt;br /&gt;
    /*done*/&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 11:33, 26 April 2017 (CEST)LeonardoF&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche&amp;diff=1776</id>
		<title>Prove pratiche</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche&amp;diff=1776"/>
		<updated>2017-04-26T09:28:37Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''Qui troverete alcune prove teoriche pratiche (laboratorio), in modo da poter discutere sull'elaborato''&lt;br /&gt;
&lt;br /&gt;
''Le prove sono svolte da studenti e servono come base per la discussione. Le soluzioni possono essere errate''&lt;br /&gt;
&lt;br /&gt;
[[Prova pratica 2015.01.21]]&lt;br /&gt;
&lt;br /&gt;
[[Prova pratica 2014.09.25]]&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1758</id>
		<title>Prova pratica 2015.01.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1758"/>
		<updated>2017-03-26T15:14:21Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2015.01.21.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 1&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot; // from https://github.com/rd235/s2argv-execs&lt;br /&gt;
#define BUFFLEN  4096 //probably there is a system constant&lt;br /&gt;
&lt;br /&gt;
int main(int argc,const char* argv[]){&lt;br /&gt;
	//take the path name and open the file&lt;br /&gt;
	FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	//read the the file and put its content in a array of pointers&lt;br /&gt;
	char commands[2][BUFFLEN]; //migliorabile&lt;br /&gt;
	char buffer[BUFFLEN];&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (fgets(buffer,sizeof(buffer),fd) != NULL){&lt;br /&gt;
		strcpy(commands[i],buffer);&lt;br /&gt;
		i ++;&lt;br /&gt;
	}&lt;br /&gt;
	//printf(&amp;quot;%s\n%s\n&amp;quot;,commands[0],commands[1] );&lt;br /&gt;
	//create a pipe&lt;br /&gt;
	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	//fork&lt;br /&gt;
	int pid;&lt;br /&gt;
	pid = fork();&lt;br /&gt;
	switch (pid){&lt;br /&gt;
	case 0 : //children&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//children's stout = pipe output&lt;br /&gt;
		dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//execution of the command&lt;br /&gt;
		execsp(commands[0]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
	default : //parent&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//father's stdin = pipe input&lt;br /&gt;
		dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//receive the comnmand&lt;br /&gt;
		execsp(commands[1]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot; // from https://github.com/rd235/s2argv-execs&lt;br /&gt;
 &lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
&lt;br /&gt;
    ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	//array_of_strings_print(&amp;amp;arrayOfStrings);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,commandNumber );&lt;br /&gt;
 	//open the pipe&lt;br /&gt;
 	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	int i = 0;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
 		if(commandNumber &amp;gt; 1) {&lt;br /&gt;
 			int pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
 						close(fpipe[0]);&lt;br /&gt;
						//children's stout = pipe output&lt;br /&gt;
						dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
						close(fpipe[1]);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
						//usleep( commandNumber* 1000000);&lt;br /&gt;
						execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
						&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		}&lt;br /&gt;
 		else{ //last command&lt;br /&gt;
 				close(fpipe[1]);&lt;br /&gt;
				//father's stdin = pipe input&lt;br /&gt;
				dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
				close(fpipe[0]);&lt;br /&gt;
				//receive the comnmand&lt;br /&gt;
				execsp(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Bash&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;
#ESERCIZIO 3&lt;br /&gt;
&lt;br /&gt;
find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
shift &lt;br /&gt;
&lt;br /&gt;
for i in $@ ; do&lt;br /&gt;
	find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
	shift&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
#ESERCIZIO 3&lt;br /&gt;
import sys&lt;br /&gt;
# os.syscall way to use linux syscalls&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
dictionary = {}&lt;br /&gt;
&lt;br /&gt;
def add(md5val,path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that insert the given file path in a dictionary&lt;br /&gt;
	using as key the given md5sum&amp;quot;&amp;quot;&amp;quot;	&lt;br /&gt;
	#in this way i avoid duplicates&lt;br /&gt;
	dictionary.setdefault(md5val,set()).add(path)&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def md5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that takes a filepath and calculate is md5sum&lt;br /&gt;
	then it calls a function to insert the file in a dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	md5val = hashlib.md5()&lt;br /&gt;
	with open(path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
		#Note that sometimes you won't be able to fit the whole file in memory. &lt;br /&gt;
		#In that case, you'll have to read chunks of 4096 bytes sequentially and feed them to the Md5 function:&lt;br /&gt;
		for chunk in iter(lambda: f.read(4096), b&amp;quot;&amp;quot;):&lt;br /&gt;
			md5val.update(chunk)&lt;br /&gt;
	add(md5val.hexdigest(),path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def movmd5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;recursive fuction that moves in the file system and call the mdadd function&lt;br /&gt;
	it takes a path in input (main checks the path given by the user) &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for root, dirs, files in os.walk(path):&lt;br /&gt;
		for f in files:&lt;br /&gt;
			#if file call the function for the md5sum &lt;br /&gt;
			md5add(os.path.join(root,f)) # os.path.join(root,f)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def printdict():&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;funtion that prints the dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for x in dictionary:&lt;br /&gt;
		#doesn't print single lines&lt;br /&gt;
		if len(dictionary[x]) &amp;gt; 1 :&lt;br /&gt;
			print('\r')&lt;br /&gt;
			for y in dictionary[x]:&lt;br /&gt;
				print(x,&amp;quot; : &amp;quot;,y)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;main checks the path and call the functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if len(args) &amp;lt; 1:&lt;br /&gt;
		args = &amp;quot;.&amp;quot;&lt;br /&gt;
	for path in args:&lt;br /&gt;
		movmd5add(path)&lt;br /&gt;
	printdict()&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
		main(sys.argv[1:])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
Scrivere un programma python o uno script bash che scandisca il sottoalbero relativo alle directory passate come&lt;br /&gt;
parametri (o alla direcotry corrente se non ci sono parametri) e fornisca in output l'elenco dei file che hanno la&lt;br /&gt;
stessa somma MD5 (i.e. l'output del comando md5sum).&lt;br /&gt;
In output ogni riga deve mostrare un elenco di pathname realtivi a file che hanno la stessa somma MD5 (che quindi&lt;br /&gt;
sono molto molto probabilmente uguali).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
def sha1sum(root, filename):&lt;br /&gt;
    sha1 = hashlib.sha1()&lt;br /&gt;
    with open(os.path.join(root, filename), &amp;quot;rb&amp;quot;) as thefile:&lt;br /&gt;
        buf = thefile.read()&lt;br /&gt;
        sha1.update(buf)&lt;br /&gt;
    return sha1.hexdigest()&lt;br /&gt;
&lt;br /&gt;
def initSha1vect(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Inizializza il dizionario utilizzando come chiave il sha1&lt;br /&gt;
    del file, e come valore il percorso del file. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    shafiles = {}&lt;br /&gt;
    for root, dirs, files in os.walk(path):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            shaKey = sha1sum(root, file)&lt;br /&gt;
            shafiles.setdefault(shaKey, [])&lt;br /&gt;
            shafiles[shaKey].append(file)&lt;br /&gt;
    return shafiles&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
    for path in args:&lt;br /&gt;
        msg = True&lt;br /&gt;
        print &amp;quot;\n&amp;quot;, path&lt;br /&gt;
        shafiles = initSha1vect(path)&lt;br /&gt;
        for k in shafiles:&lt;br /&gt;
            if len(shafiles[k]) &amp;gt; 1:&lt;br /&gt;
                msg = False&lt;br /&gt;
                print k, &amp;quot;\t&amp;quot;, shafiles[k]&lt;br /&gt;
        if msg:&lt;br /&gt;
            print &amp;quot;Nessun file con lo stesso sha1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
	main(sys.argv[1:])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:S.G|S.G]] ([[User talk:S.G|talk]]) 14:39, 18 November 2016 (CET)&amp;lt;br&amp;gt;&lt;br /&gt;
Ho scritto una possibile soluzione dell'esercizio 3&lt;br /&gt;
&lt;br /&gt;
'''perch&amp;amp;eacute; proporre una soluzione in un linguaggio che non ho ancora spiegato?'''[[User:Renzo|Renzo]] ([[User talk:Renzo|talk]]) 19:36, 21 November 2016 (CET)&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1757</id>
		<title>Prova pratica 2015.01.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1757"/>
		<updated>2017-03-26T15:12:21Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2015.01.21.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 1&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;quot;execs.h&amp;quot; // from https://github.com/rd235/s2argv-execs&lt;br /&gt;
#define BUFFLEN  4096 //probably there is a system constant&lt;br /&gt;
&lt;br /&gt;
int main(int argc,const char* argv[]){&lt;br /&gt;
	//take the path name and open the file&lt;br /&gt;
	FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	//read the the file and put its content in a array of pointers&lt;br /&gt;
	char commands[2][BUFFLEN]; //migliorabile&lt;br /&gt;
	char buffer[BUFFLEN];&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (fgets(buffer,sizeof(buffer),fd) != NULL){&lt;br /&gt;
		strcpy(commands[i],buffer);&lt;br /&gt;
		i ++;&lt;br /&gt;
	}&lt;br /&gt;
	//printf(&amp;quot;%s\n%s\n&amp;quot;,commands[0],commands[1] );&lt;br /&gt;
	//create a pipe&lt;br /&gt;
	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	//fork&lt;br /&gt;
	int pid;&lt;br /&gt;
	pid = fork();&lt;br /&gt;
	switch (pid){&lt;br /&gt;
	case 0 : //children&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//children's stout = pipe output&lt;br /&gt;
		dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//execution of the command&lt;br /&gt;
		execsp(commands[0]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
	default : //parent&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//father's stdin = pipe input&lt;br /&gt;
		dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//receive the comnmand&lt;br /&gt;
		execsp(commands[1]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
&lt;br /&gt;
    ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	//array_of_strings_print(&amp;amp;arrayOfStrings);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,commandNumber );&lt;br /&gt;
 	//open the pipe&lt;br /&gt;
 	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	int i = 0;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
 		if(commandNumber &amp;gt; 1) {&lt;br /&gt;
 			int pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
 						close(fpipe[0]);&lt;br /&gt;
						//children's stout = pipe output&lt;br /&gt;
						dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
						close(fpipe[1]);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
						//usleep( commandNumber* 1000000);&lt;br /&gt;
						system(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
						commandNumber = 0;&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		}&lt;br /&gt;
 		else{ //last command&lt;br /&gt;
 				close(fpipe[1]);&lt;br /&gt;
				//father's stdin = pipe input&lt;br /&gt;
				dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
				close(fpipe[0]);&lt;br /&gt;
				//receive the comnmand&lt;br /&gt;
				system(arrayOfStrings.strings[i]);&lt;br /&gt;
				commandNumber --;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Bash&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;
#ESERCIZIO 3&lt;br /&gt;
&lt;br /&gt;
find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
shift &lt;br /&gt;
&lt;br /&gt;
for i in $@ ; do&lt;br /&gt;
	find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
	shift&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
#ESERCIZIO 3&lt;br /&gt;
import sys&lt;br /&gt;
# os.syscall way to use linux syscalls&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
dictionary = {}&lt;br /&gt;
&lt;br /&gt;
def add(md5val,path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that insert the given file path in a dictionary&lt;br /&gt;
	using as key the given md5sum&amp;quot;&amp;quot;&amp;quot;	&lt;br /&gt;
	#in this way i avoid duplicates&lt;br /&gt;
	dictionary.setdefault(md5val,set()).add(path)&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def md5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that takes a filepath and calculate is md5sum&lt;br /&gt;
	then it calls a function to insert the file in a dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	md5val = hashlib.md5()&lt;br /&gt;
	with open(path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
		#Note that sometimes you won't be able to fit the whole file in memory. &lt;br /&gt;
		#In that case, you'll have to read chunks of 4096 bytes sequentially and feed them to the Md5 function:&lt;br /&gt;
		for chunk in iter(lambda: f.read(4096), b&amp;quot;&amp;quot;):&lt;br /&gt;
			md5val.update(chunk)&lt;br /&gt;
	add(md5val.hexdigest(),path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def movmd5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;recursive fuction that moves in the file system and call the mdadd function&lt;br /&gt;
	it takes a path in input (main checks the path given by the user) &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for root, dirs, files in os.walk(path):&lt;br /&gt;
		for f in files:&lt;br /&gt;
			#if file call the function for the md5sum &lt;br /&gt;
			md5add(os.path.join(root,f)) # os.path.join(root,f)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def printdict():&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;funtion that prints the dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for x in dictionary:&lt;br /&gt;
		#doesn't print single lines&lt;br /&gt;
		if len(dictionary[x]) &amp;gt; 1 :&lt;br /&gt;
			print('\r')&lt;br /&gt;
			for y in dictionary[x]:&lt;br /&gt;
				print(x,&amp;quot; : &amp;quot;,y)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;main checks the path and call the functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if len(args) &amp;lt; 1:&lt;br /&gt;
		args = &amp;quot;.&amp;quot;&lt;br /&gt;
	for path in args:&lt;br /&gt;
		movmd5add(path)&lt;br /&gt;
	printdict()&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
		main(sys.argv[1:])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
Scrivere un programma python o uno script bash che scandisca il sottoalbero relativo alle directory passate come&lt;br /&gt;
parametri (o alla direcotry corrente se non ci sono parametri) e fornisca in output l'elenco dei file che hanno la&lt;br /&gt;
stessa somma MD5 (i.e. l'output del comando md5sum).&lt;br /&gt;
In output ogni riga deve mostrare un elenco di pathname realtivi a file che hanno la stessa somma MD5 (che quindi&lt;br /&gt;
sono molto molto probabilmente uguali).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
def sha1sum(root, filename):&lt;br /&gt;
    sha1 = hashlib.sha1()&lt;br /&gt;
    with open(os.path.join(root, filename), &amp;quot;rb&amp;quot;) as thefile:&lt;br /&gt;
        buf = thefile.read()&lt;br /&gt;
        sha1.update(buf)&lt;br /&gt;
    return sha1.hexdigest()&lt;br /&gt;
&lt;br /&gt;
def initSha1vect(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Inizializza il dizionario utilizzando come chiave il sha1&lt;br /&gt;
    del file, e come valore il percorso del file. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    shafiles = {}&lt;br /&gt;
    for root, dirs, files in os.walk(path):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            shaKey = sha1sum(root, file)&lt;br /&gt;
            shafiles.setdefault(shaKey, [])&lt;br /&gt;
            shafiles[shaKey].append(file)&lt;br /&gt;
    return shafiles&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
    for path in args:&lt;br /&gt;
        msg = True&lt;br /&gt;
        print &amp;quot;\n&amp;quot;, path&lt;br /&gt;
        shafiles = initSha1vect(path)&lt;br /&gt;
        for k in shafiles:&lt;br /&gt;
            if len(shafiles[k]) &amp;gt; 1:&lt;br /&gt;
                msg = False&lt;br /&gt;
                print k, &amp;quot;\t&amp;quot;, shafiles[k]&lt;br /&gt;
        if msg:&lt;br /&gt;
            print &amp;quot;Nessun file con lo stesso sha1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
	main(sys.argv[1:])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:S.G|S.G]] ([[User talk:S.G|talk]]) 14:39, 18 November 2016 (CET)&amp;lt;br&amp;gt;&lt;br /&gt;
Ho scritto una possibile soluzione dell'esercizio 3&lt;br /&gt;
&lt;br /&gt;
'''perch&amp;amp;eacute; proporre una soluzione in un linguaggio che non ho ancora spiegato?'''[[User:Renzo|Renzo]] ([[User talk:Renzo|talk]]) 19:36, 21 November 2016 (CET)&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1756</id>
		<title>Prova pratica 2015.01.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1756"/>
		<updated>2017-03-26T13:42:24Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2015.01.21.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 1&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#define BUFFLEN  4096 //probably there is a system constant&lt;br /&gt;
&lt;br /&gt;
int main(int argc,const char* argv[]){&lt;br /&gt;
	//take the path name and open the file&lt;br /&gt;
	FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	//read the the file and put its content in a array of pointers&lt;br /&gt;
	char commands[2][BUFFLEN]; //migliorabile&lt;br /&gt;
	char buffer[BUFFLEN];&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (fgets(buffer,sizeof(buffer),fd) != NULL){&lt;br /&gt;
		strcpy(commands[i],buffer);&lt;br /&gt;
		i ++;&lt;br /&gt;
	}&lt;br /&gt;
	//printf(&amp;quot;%s\n%s\n&amp;quot;,commands[0],commands[1] );&lt;br /&gt;
	//create a pipe&lt;br /&gt;
	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	//fork&lt;br /&gt;
	int pid;&lt;br /&gt;
	pid = fork();&lt;br /&gt;
	switch (pid){&lt;br /&gt;
	case 0 : //children&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//children's stout = pipe output&lt;br /&gt;
		dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//execution of the command&lt;br /&gt;
		system(commands[0]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
	default : //parent&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//father's stdin = pipe input&lt;br /&gt;
		dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//receive the comnmand&lt;br /&gt;
		system(commands[1]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
&lt;br /&gt;
    ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	//array_of_strings_print(&amp;amp;arrayOfStrings);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,commandNumber );&lt;br /&gt;
 	//open the pipe&lt;br /&gt;
 	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	int i = 0;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
 		if(commandNumber &amp;gt; 1) {&lt;br /&gt;
 			int pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
 						close(fpipe[0]);&lt;br /&gt;
						//children's stout = pipe output&lt;br /&gt;
						dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
						close(fpipe[1]);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
						//usleep( commandNumber* 1000000);&lt;br /&gt;
						system(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
						commandNumber = 0;&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		}&lt;br /&gt;
 		else{ //last command&lt;br /&gt;
 				close(fpipe[1]);&lt;br /&gt;
				//father's stdin = pipe input&lt;br /&gt;
				dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
				close(fpipe[0]);&lt;br /&gt;
				//receive the comnmand&lt;br /&gt;
				system(arrayOfStrings.strings[i]);&lt;br /&gt;
				commandNumber --;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Bash&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;
#ESERCIZIO 3&lt;br /&gt;
&lt;br /&gt;
find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
shift &lt;br /&gt;
&lt;br /&gt;
for i in $@ ; do&lt;br /&gt;
	find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
	shift&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
#ESERCIZIO 3&lt;br /&gt;
import sys&lt;br /&gt;
# os.syscall way to use linux syscalls&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
dictionary = {}&lt;br /&gt;
&lt;br /&gt;
def add(md5val,path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that insert the given file path in a dictionary&lt;br /&gt;
	using as key the given md5sum&amp;quot;&amp;quot;&amp;quot;	&lt;br /&gt;
	#in this way i avoid duplicates&lt;br /&gt;
	dictionary.setdefault(md5val,set()).add(path)&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def md5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that takes a filepath and calculate is md5sum&lt;br /&gt;
	then it calls a function to insert the file in a dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	md5val = hashlib.md5()&lt;br /&gt;
	with open(path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
		#Note that sometimes you won't be able to fit the whole file in memory. &lt;br /&gt;
		#In that case, you'll have to read chunks of 4096 bytes sequentially and feed them to the Md5 function:&lt;br /&gt;
		for chunk in iter(lambda: f.read(4096), b&amp;quot;&amp;quot;):&lt;br /&gt;
			md5val.update(chunk)&lt;br /&gt;
	add(md5val.hexdigest(),path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def movmd5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;recursive fuction that moves in the file system and call the mdadd function&lt;br /&gt;
	it takes a path in input (main checks the path given by the user) &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for root, dirs, files in os.walk(path):&lt;br /&gt;
		for f in files:&lt;br /&gt;
			#if file call the function for the md5sum &lt;br /&gt;
			md5add(os.path.join(root,f)) # os.path.join(root,f)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def printdict():&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;funtion that prints the dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for x in dictionary:&lt;br /&gt;
		#doesn't print single lines&lt;br /&gt;
		if len(dictionary[x]) &amp;gt; 1 :&lt;br /&gt;
			print('\r')&lt;br /&gt;
			for y in dictionary[x]:&lt;br /&gt;
				print(x,&amp;quot; : &amp;quot;,y)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;main checks the path and call the functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if len(args) &amp;lt; 1:&lt;br /&gt;
		args = &amp;quot;.&amp;quot;&lt;br /&gt;
	for path in args:&lt;br /&gt;
		movmd5add(path)&lt;br /&gt;
	printdict()&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
		main(sys.argv[1:])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
Scrivere un programma python o uno script bash che scandisca il sottoalbero relativo alle directory passate come&lt;br /&gt;
parametri (o alla direcotry corrente se non ci sono parametri) e fornisca in output l'elenco dei file che hanno la&lt;br /&gt;
stessa somma MD5 (i.e. l'output del comando md5sum).&lt;br /&gt;
In output ogni riga deve mostrare un elenco di pathname realtivi a file che hanno la stessa somma MD5 (che quindi&lt;br /&gt;
sono molto molto probabilmente uguali).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
def sha1sum(root, filename):&lt;br /&gt;
    sha1 = hashlib.sha1()&lt;br /&gt;
    with open(os.path.join(root, filename), &amp;quot;rb&amp;quot;) as thefile:&lt;br /&gt;
        buf = thefile.read()&lt;br /&gt;
        sha1.update(buf)&lt;br /&gt;
    return sha1.hexdigest()&lt;br /&gt;
&lt;br /&gt;
def initSha1vect(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Inizializza il dizionario utilizzando come chiave il sha1&lt;br /&gt;
    del file, e come valore il percorso del file. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    shafiles = {}&lt;br /&gt;
    for root, dirs, files in os.walk(path):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            shaKey = sha1sum(root, file)&lt;br /&gt;
            shafiles.setdefault(shaKey, [])&lt;br /&gt;
            shafiles[shaKey].append(file)&lt;br /&gt;
    return shafiles&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
    for path in args:&lt;br /&gt;
        msg = True&lt;br /&gt;
        print &amp;quot;\n&amp;quot;, path&lt;br /&gt;
        shafiles = initSha1vect(path)&lt;br /&gt;
        for k in shafiles:&lt;br /&gt;
            if len(shafiles[k]) &amp;gt; 1:&lt;br /&gt;
                msg = False&lt;br /&gt;
                print k, &amp;quot;\t&amp;quot;, shafiles[k]&lt;br /&gt;
        if msg:&lt;br /&gt;
            print &amp;quot;Nessun file con lo stesso sha1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
	main(sys.argv[1:])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:S.G|S.G]] ([[User talk:S.G|talk]]) 14:39, 18 November 2016 (CET)&amp;lt;br&amp;gt;&lt;br /&gt;
Ho scritto una possibile soluzione dell'esercizio 3&lt;br /&gt;
&lt;br /&gt;
'''perch&amp;amp;eacute; proporre una soluzione in un linguaggio che non ho ancora spiegato?'''[[User:Renzo|Renzo]] ([[User talk:Renzo|talk]]) 19:36, 21 November 2016 (CET)&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1755</id>
		<title>Prova pratica 2015.01.21</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prova_pratica_2015.01.21&amp;diff=1755"/>
		<updated>2017-03-26T13:39:43Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Testo: [http://www.cs.unibo.it/~renzo/so/pratiche/2015.01.21.pdf]&lt;br /&gt;
&lt;br /&gt;
Esercizio 1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 1&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;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#define BUFFLEN  4096 //probably there is a system constant&lt;br /&gt;
&lt;br /&gt;
int main(int argc,const char* argv[]){&lt;br /&gt;
	//take the path name and open the file&lt;br /&gt;
	FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
	//read the the file and put its content in a array of pointers&lt;br /&gt;
	char commands[2][BUFFLEN]; //migliorabile&lt;br /&gt;
	char buffer[BUFFLEN];&lt;br /&gt;
	int i = 0;&lt;br /&gt;
	while (fgets(buffer,sizeof(buffer),fd) != NULL){&lt;br /&gt;
		strcpy(commands[i],buffer);&lt;br /&gt;
		i ++;&lt;br /&gt;
	}&lt;br /&gt;
	//printf(&amp;quot;%s\n%s\n&amp;quot;,commands[0],commands[1] );&lt;br /&gt;
	//create a pipe&lt;br /&gt;
	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	//fork&lt;br /&gt;
	int pid;&lt;br /&gt;
	pid = fork();&lt;br /&gt;
	switch (pid){&lt;br /&gt;
	case 0 : //children&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//children's stout = pipe output&lt;br /&gt;
		dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//execution of the command&lt;br /&gt;
		system(commands[0]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
&lt;br /&gt;
	default : //parent&lt;br /&gt;
		&lt;br /&gt;
		close(fpipe[1]);&lt;br /&gt;
		//father's stdin = pipe input&lt;br /&gt;
		dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
		close(fpipe[0]);&lt;br /&gt;
		//receive the comnmand&lt;br /&gt;
		system(commands[1]);&lt;br /&gt;
		&lt;br /&gt;
		break;&lt;br /&gt;
	}	&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;C&amp;quot;&amp;gt;&lt;br /&gt;
//ESERCIZIO 2&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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
#define AOS_LENSTEP 8&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * Define a struct for managing and array of pointer to strings.&lt;br /&gt;
 */&lt;br /&gt;
struct array_of_strings {&lt;br /&gt;
    char **strings;&lt;br /&gt;
    size_t currentlength; //the length of number of string in memory&lt;br /&gt;
    size_t arraylength; //the length of memory allocated&lt;br /&gt;
};&lt;br /&gt;
 &lt;br /&gt;
typedef struct array_of_strings array_of_strings;&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_add(array_of_strings *arrayOfStrings, char *string) {&lt;br /&gt;
    //if there is not enough space for the string increase it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;gt;= arrayOfStrings-&amp;gt;arraylength) {&lt;br /&gt;
        //increase the array length by the size of a string pointer&lt;br /&gt;
        size_t newlength = arrayOfStrings-&amp;gt;arraylength + AOS_LENSTEP;&lt;br /&gt;
        //reallocate the arrayOfString with the new size&lt;br /&gt;
        char **new_string = realloc(arrayOfStrings-&amp;gt;strings, newlength * sizeof(arrayOfStrings-&amp;gt;strings[0]));&lt;br /&gt;
        //if the reallocation is successful&lt;br /&gt;
        if (new_string != NULL) {&lt;br /&gt;
            arrayOfStrings-&amp;gt;arraylength = newlength;&lt;br /&gt;
            arrayOfStrings-&amp;gt;strings = new_string;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //if there is enough space for the string insert it&lt;br /&gt;
    if (arrayOfStrings-&amp;gt;currentlength &amp;lt; arrayOfStrings-&amp;gt;arraylength)&lt;br /&gt;
        //strdup return a pointer to a duplicate of the string&lt;br /&gt;
        arrayOfStrings-&amp;gt;strings[arrayOfStrings-&amp;gt;currentlength++] = strdup(string);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
void array_of_strings_print(array_of_strings *v) {&lt;br /&gt;
    size_t i;&lt;br /&gt;
    for (i = 0; i &amp;lt; v-&amp;gt;currentlength; i++)&lt;br /&gt;
        printf(&amp;quot;[%3lu]: %s\n&amp;quot;, i, v-&amp;gt;strings[i]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
	int commandNumber= 0;&lt;br /&gt;
    char* line = NULL;&lt;br /&gt;
    size_t lineLength = 0;&lt;br /&gt;
&lt;br /&gt;
    ssize_t numberOfCharactersRead;&lt;br /&gt;
    static array_of_strings arrayOfStrings;&lt;br /&gt;
    FILE* fd = fopen(argv[1],&amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    while ((numberOfCharactersRead = getline(&amp;amp;line, &amp;amp;lineLength, fd)) &amp;gt;= 0) {&lt;br /&gt;
        if (line[numberOfCharactersRead - 1] == '\n')&lt;br /&gt;
            line[numberOfCharactersRead - 1] = 0;&lt;br /&gt;
        array_of_strings_add(&amp;amp;arrayOfStrings, line);&lt;br /&gt;
        commandNumber ++;&lt;br /&gt;
    }&lt;br /&gt;
 	free(line);&lt;br /&gt;
 	//array_of_strings_print(&amp;amp;arrayOfStrings);&lt;br /&gt;
 	//printf(&amp;quot;%d\n&amp;quot;,commandNumber );&lt;br /&gt;
 	//open the pipe&lt;br /&gt;
 	int fpipe[2];&lt;br /&gt;
	pipe(fpipe); //0 reading,1 writing&lt;br /&gt;
	int i = 0;&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
 	while(commandNumber &amp;gt; 0 ){&lt;br /&gt;
 		if(commandNumber &amp;gt; 1) {&lt;br /&gt;
 			int pid = fork();&lt;br /&gt;
 			switch(pid){&lt;br /&gt;
 				case 0: //children&lt;br /&gt;
 						close(fpipe[0]);&lt;br /&gt;
						//children's stout = pipe output&lt;br /&gt;
						dup2(fpipe[1],STDOUT_FILENO);&lt;br /&gt;
						close(fpipe[1]);&lt;br /&gt;
						//execution of the command&lt;br /&gt;
						//usleep( commandNumber* 1000000);&lt;br /&gt;
						system(arrayOfStrings.strings[i]);&lt;br /&gt;
				&lt;br /&gt;
						commandNumber = 0;&lt;br /&gt;
 						break;&lt;br /&gt;
 				default: //parent &lt;br /&gt;
 						commandNumber --;&lt;br /&gt;
 						i ++;&lt;br /&gt;
 						break;&lt;br /&gt;
 			}&lt;br /&gt;
 		}&lt;br /&gt;
 		else{ //last command&lt;br /&gt;
 				close(fpipe[1]);&lt;br /&gt;
				//father's stdin = pipe input&lt;br /&gt;
				dup2(fpipe[0],STDIN_FILENO);&lt;br /&gt;
				close(fpipe[0]);&lt;br /&gt;
				//receive the comnmand&lt;br /&gt;
				system(arrayOfStrings.strings[i]);&lt;br /&gt;
				commandNumber --;&lt;br /&gt;
 		}&lt;br /&gt;
 	}&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Bash&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;
#ESERCISIO 3&lt;br /&gt;
&lt;br /&gt;
find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
shift &lt;br /&gt;
&lt;br /&gt;
for i in $@ ; do&lt;br /&gt;
	find $1 -exec md5sum {} \; |sort | uniq  --all-repeated=separate --check-chars=32&lt;br /&gt;
	shift&lt;br /&gt;
&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3 Script Python&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python3&lt;br /&gt;
#ESERCIZIO 3&lt;br /&gt;
import sys&lt;br /&gt;
# os.syscall way to use linux syscalls&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
dictionary = {}&lt;br /&gt;
&lt;br /&gt;
def add(md5val,path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that insert the given file path in a dictionary&lt;br /&gt;
	using as key the given md5sum&amp;quot;&amp;quot;&amp;quot;	&lt;br /&gt;
	#in this way i avoid duplicates&lt;br /&gt;
	dictionary.setdefault(md5val,set()).add(path)&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
def md5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;function that takes a filepath and calculate is md5sum&lt;br /&gt;
	then it calls a function to insert the file in a dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	md5val = hashlib.md5()&lt;br /&gt;
	with open(path, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
		#Note that sometimes you won't be able to fit the whole file in memory. &lt;br /&gt;
		#In that case, you'll have to read chunks of 4096 bytes sequentially and feed them to the Md5 function:&lt;br /&gt;
		for chunk in iter(lambda: f.read(4096), b&amp;quot;&amp;quot;):&lt;br /&gt;
			md5val.update(chunk)&lt;br /&gt;
	add(md5val.hexdigest(),path)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def movmd5add(path):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;recursive fuction that moves in the file system and call the mdadd function&lt;br /&gt;
	it takes a path in input (main checks the path given by the user) &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for root, dirs, files in os.walk(path):&lt;br /&gt;
		for f in files:&lt;br /&gt;
			#if file call the function for the md5sum &lt;br /&gt;
			md5add(os.path.join(root,f)) # os.path.join(root,f)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def printdict():&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;funtion that prints the dictionary&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	for x in dictionary:&lt;br /&gt;
		#doesn't print single lines&lt;br /&gt;
		if len(dictionary[x]) &amp;gt; 1 :&lt;br /&gt;
			print('\r')&lt;br /&gt;
			for y in dictionary[x]:&lt;br /&gt;
				print(x,&amp;quot; : &amp;quot;,y)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
	&amp;quot;&amp;quot;&amp;quot;main checks the path and call the functions&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
	if len(args) &amp;lt; 1:&lt;br /&gt;
		args = &amp;quot;.&amp;quot;&lt;br /&gt;
	for path in args:&lt;br /&gt;
		movmd5add(path)&lt;br /&gt;
	printdict()&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
		main(sys.argv[1:])&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--[[User:LeonardoF|LeonardoF]] ([[User talk:LeonardoF|talk]]) 15:39, 26 March 2017 (CEST)LeonardoF&lt;br /&gt;
&lt;br /&gt;
Esercizio 3&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Esercizio 3: Script bash o Python: (10 punti):&lt;br /&gt;
Scrivere un programma python o uno script bash che scandisca il sottoalbero relativo alle directory passate come&lt;br /&gt;
parametri (o alla direcotry corrente se non ci sono parametri) e fornisca in output l'elenco dei file che hanno la&lt;br /&gt;
stessa somma MD5 (i.e. l'output del comando md5sum).&lt;br /&gt;
In output ogni riga deve mostrare un elenco di pathname realtivi a file che hanno la stessa somma MD5 (che quindi&lt;br /&gt;
sono molto molto probabilmente uguali).&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import hashlib&lt;br /&gt;
&lt;br /&gt;
def sha1sum(root, filename):&lt;br /&gt;
    sha1 = hashlib.sha1()&lt;br /&gt;
    with open(os.path.join(root, filename), &amp;quot;rb&amp;quot;) as thefile:&lt;br /&gt;
        buf = thefile.read()&lt;br /&gt;
        sha1.update(buf)&lt;br /&gt;
    return sha1.hexdigest()&lt;br /&gt;
&lt;br /&gt;
def initSha1vect(path):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Inizializza il dizionario utilizzando come chiave il sha1&lt;br /&gt;
    del file, e come valore il percorso del file. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    shafiles = {}&lt;br /&gt;
    for root, dirs, files in os.walk(path):&lt;br /&gt;
        for file in files:&lt;br /&gt;
            shaKey = sha1sum(root, file)&lt;br /&gt;
            shafiles.setdefault(shaKey, [])&lt;br /&gt;
            shafiles[shaKey].append(file)&lt;br /&gt;
    return shafiles&lt;br /&gt;
&lt;br /&gt;
def main(args):&lt;br /&gt;
    for path in args:&lt;br /&gt;
        msg = True&lt;br /&gt;
        print &amp;quot;\n&amp;quot;, path&lt;br /&gt;
        shafiles = initSha1vect(path)&lt;br /&gt;
        for k in shafiles:&lt;br /&gt;
            if len(shafiles[k]) &amp;gt; 1:&lt;br /&gt;
                msg = False&lt;br /&gt;
                print k, &amp;quot;\t&amp;quot;, shafiles[k]&lt;br /&gt;
        if msg:&lt;br /&gt;
            print &amp;quot;Nessun file con lo stesso sha1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
	main(sys.argv[1:])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:S.G|S.G]] ([[User talk:S.G|talk]]) 14:39, 18 November 2016 (CET)&amp;lt;br&amp;gt;&lt;br /&gt;
Ho scritto una possibile soluzione dell'esercizio 3&lt;br /&gt;
&lt;br /&gt;
'''perch&amp;amp;eacute; proporre una soluzione in un linguaggio che non ho ancora spiegato?'''[[User:Renzo|Renzo]] ([[User talk:Renzo|talk]]) 19:36, 21 November 2016 (CET)&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=User:LeonardoF&amp;diff=1754</id>
		<title>User:LeonardoF</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=User:LeonardoF&amp;diff=1754"/>
		<updated>2017-03-26T13:33:10Z</updated>

		<summary type="html">&lt;p&gt;LeonardoF: Created page with &amp;quot;mailto:leonardo.frioli@studio.unibo.it&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;mailto:leonardo.frioli@studio.unibo.it&lt;/div&gt;</summary>
		<author><name>LeonardoF</name></author>
	</entry>
</feed>