<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prove_pratiche_2018</id>
	<title>Prove pratiche 2018 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://so.v2.cs.unibo.it/wiki/index.php?action=history&amp;feed=atom&amp;title=Prove_pratiche_2018"/>
	<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2018&amp;action=history"/>
	<updated>2026-05-14T15:41:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2018&amp;diff=2582&amp;oldid=prev</id>
		<title>Acsor: Created page with &quot;== Esame Pratico 21/09/2018 == http://www.cs.unibo.it/~renzo/so/pratiche/2018.09.21.pdf === Esercizio 1 === &lt;source lang=&quot;c&quot;&gt;        #define _GNU_SOURCE        #include &lt;sys/s...&quot;</title>
		<link rel="alternate" type="text/html" href="https://so.v2.cs.unibo.it/wiki/index.php?title=Prove_pratiche_2018&amp;diff=2582&amp;oldid=prev"/>
		<updated>2020-08-30T08:15:40Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Esame Pratico 21/09/2018 == http://www.cs.unibo.it/~renzo/so/pratiche/2018.09.21.pdf === Esercizio 1 === &amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;        #define _GNU_SOURCE        #include &amp;lt;sys/s...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Esame Pratico 21/09/2018 ==&lt;br /&gt;
http://www.cs.unibo.it/~renzo/so/pratiche/2018.09.21.pdf&lt;br /&gt;
=== Esercizio 1 ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
       #define _GNU_SOURCE&lt;br /&gt;
       #include &amp;lt;sys/signalfd.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;signal.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;time.h&amp;gt;&lt;br /&gt;
       #include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char * argv[]){&lt;br /&gt;
        sigset_t mask;&lt;br /&gt;
        struct signalfd_siginfo fdsi;&lt;br /&gt;
        int fd;&lt;br /&gt;
        char* t;&lt;br /&gt;
        char* filename;&lt;br /&gt;
&lt;br /&gt;
        sigemptyset(&amp;amp;mask);&lt;br /&gt;
        sigaddset(&amp;amp;mask, SIGUSR1);&lt;br /&gt;
        sigaddset(&amp;amp;mask, SIGUSR2);&lt;br /&gt;
        sigprocmask(SIG_SETMASK, &amp;amp;mask, NULL);&lt;br /&gt;
&lt;br /&gt;
        int sigfd = signalfd(-1, &amp;amp;mask, 0);&lt;br /&gt;
&lt;br /&gt;
        for(;;){&lt;br /&gt;
                read(sigfd, &amp;amp;fdsi, sizeof(struct signalfd_siginfo));&lt;br /&gt;
                if(fdsi.ssi_signo == SIGUSR1){&lt;br /&gt;
                        asprintf(&amp;amp;filename, &amp;quot;./%u&amp;quot;, fdsi.ssi_pid);&lt;br /&gt;
                        fd = open(filename, O_APPEND | O_CREAT | O_WRONLY);&lt;br /&gt;
                        time_t stime = time(NULL);&lt;br /&gt;
                        t = ctime(&amp;amp;stime);&lt;br /&gt;
                        write(fd, t, sizeof(char)*strlen(t));&lt;br /&gt;
                        close(fd);&lt;br /&gt;
                        }&lt;br /&gt;
                if(fdsi.ssi_signo == SIGUSR2){&lt;br /&gt;
                        asprintf(&amp;amp;filename, &amp;quot;./%u&amp;quot;, fdsi.ssi_pid);&lt;br /&gt;
                        fd = open(filename, O_APPEND | O_CREAT | O_WRONLY);&lt;br /&gt;
                        time_t stime = time(NULL);&lt;br /&gt;
                        t = ctime(&amp;amp;stime);&lt;br /&gt;
                        write(fd, t, sizeof(char)*strlen(t));&lt;br /&gt;
                        close(fd);&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
dovrebbe stampare anche il nome del segnale prima di stampare il tempo ma per il resto va bene&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Esercizio 3 ===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
import re&lt;br /&gt;
dict = {}&lt;br /&gt;
&lt;br /&gt;
def func(a):&lt;br /&gt;
    os.chdir(a)&lt;br /&gt;
    for root, dirs, files in os.walk(&amp;quot;.&amp;quot;):&lt;br /&gt;
      for filename in files:&lt;br /&gt;
        try:&lt;br /&gt;
          fl =file(filename)&lt;br /&gt;
          firstline = fl.readline()&lt;br /&gt;
          fl.close()&lt;br /&gt;
        except IOError: # caso di file che non riesce ad aprire&lt;br /&gt;
          #print(&amp;quot;could not read&amp;quot;, file)&lt;br /&gt;
          pass&lt;br /&gt;
        if (re.match('^#!', firstline)):&lt;br /&gt;
          dict.setdefault(firstline, []) #firstline include anche il carattere \n, quindi quando si stampa va anche a capo&lt;br /&gt;
          dict[firstline].append(filename)&lt;br /&gt;
    for k in dict.keys():&lt;br /&gt;
      print k&lt;br /&gt;
      for v in dict[k]:&lt;br /&gt;
        print v&lt;br /&gt;
      #print(&amp;quot; &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
  if (len(sys.argv)==1):&lt;br /&gt;
    dir = &amp;quot;.&amp;quot;&lt;br /&gt;
  else:&lt;br /&gt;
    dir = sys.argv[1]&lt;br /&gt;
  func(dir)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Acsor</name></author>
	</entry>
</feed>