• Aucun résultat trouvé

#include <unistd.h&gt

N/A
N/A
Protected

Academic year: 2022

Partager "#include <unistd.h&gt"

Copied!
5
0
0

Texte intégral

(1)

798;:<=2>(?A@(BDC!EFGFG=HJIK>MLNBPORQ;:SOTEH3<GF

UDVXWZY\[]^`_

acbdb _e

acbdbcf

gihDjkZlnmlojqp rtsuj!vxwymzzj!{({yj}|~j!{€kG‚loj!{({yƒ~{

„…) * D† 2&0‡ 201ˆ1346c"*0),)*4x‰"5Š‹nŒ046‰"*o‡6*"Žc 60Š‹nŒ4‰"5n13‘’&)"*

“”Ž)2•–)&013†0‡0Š’'—x† 2&˜)2’†c™ 2•"55•‰"*2 2 š*"*" †’0)*4›)&Žœc†5"*, 2 2ŠZ&0

6’)Œ &5 "ˆ,"5‚‰žž)&013†20‡0•† &)2œ*"5 \*‡0’"(13*† ,"*•†c™ 2xŸ‘*š2&\

‡0 2&0†’“† 2&)2Š

  #include <stdio.h>

¡ #include <unistd.h>

¢ #include <errno.h>

£ #include <sys/types.h>

¤ #include <sched.h>

¥ #include <signal.h>

¦ #include <sys/wait.h>

§¨

 ª© #define NB_FILS 5

 - 

 $¡ volatile long cpt = 0;

 $¢ static int gentilesse;

 «£

 $¤ int fils;

 -¥

 -¦ void handler (int iSig)

 $§ {

 ¨

if (cpt != 0)

¡© {

¡  fprintf (stdout," Fils %u (nice %2d) Compteur = %9ld\n",

¡-¡ getpid(),

¡-¢ gentilesse,

¡ª£ cpt);

¡-¤ exit(0);

¡¥ }

¡¦ }

¡-§

¡ ¨

¢© int main (int argc, char **argv)

¢  {

¢-¡ int i;

¢-¢ pid_t pid;

¢ª£ // int fils;

¢-¤

¢¥ /* Creation d un groupe de pcs */

(2)

¢¦ setpgid(0,0);

¢-§

¢ ¨

signal (SIGUSR1, handler);

£©

£2  for (fils = 0; fils < NB_FILS; fils ++)

£­¡ {

£­¢ if ((pid = fork())< 0)

£-£ {

£­¤ perror ("fork");

£2¥ exit (1);

£2¦ }

£­§

£ ¨

if (pid != 0)

¤© continue;

¤ 

¤-¡ printf ("fils %d\n", fils);

¤-¢ gentilesse = fils * ( 20 / (NB_FILS - 1));

¤ª£

¤-¤ if (nice (gentilesse) < 0)

¤¥ {

¤¦ perror ("nice");

¤-§ exit (-1);

¤ ¨

}

¥ª©

¥-  /* attente signal de demarrage */

¥$¡ pause();

¥$¢

¥«£ printf ("fils %d\n", fils);

¥$¤

¥-¥ /* comptage */

¥-¦ while (1)

¥$§ cpt++;

¥¨

}

¦ª©

¦-  /* pere */

¦$¡ printf ("pere\n");

¦$¢ signal (SIGUSR1, SIG_IGN);

¦«£

¦$¤ sleep(1);

¦-¥ kill ( - getpgid (0), SIGUSR1);

¦-¦

¦$§ sleep(5);

¦¨

§© kill ( - getpgid (0), SIGUSR1);

§ 

§-¡ while (wait(NULL)>0)

§-¢ ;

§ª£ printf ("bye\n");

§-¤ exit(0);

§¥

§¦ /*

§-§ return(0);*/

§ ¨

}

(3)

„…) * J† &‡0 13134("5)›‰"5Šc'—‰"5"5’) ˆ›*13 , ® )&Žœ&0J 2†c.“#&0 21ˆ* Š

'—†’™ "*0) 2“D*1ˆ … 2†c2¹2¹.yºP)&ŽŠ6%»)Œ4!./&05…46"*213 ¼&1•c œ"c˜0 ,‘‡"c3‰"5Š

%A"5x 2)†2&P),*13 Žœ",‰"5! 2½- 213 •&0~*1ˆ Š

  #include <stdio.h>

¡ #include <unistd.h>

¢ #include <errno.h>

£ #include <sys/types.h>

¤ #include <sched.h>

¥ #include <signal.h>

¦ #include <sys/wait.h>

§ #include <sys/time.h>¨

 ª© typedef struct itimerval Timer;

 -  Timer timer;

 $¡ #define NB_FILS 5

 $¢

 «£ volatile long cpt = 0;

 $¤ static int gentilesse;

 -¥

 -¦ int fils;

 $§

 ¨

void TimerFils(Timer * timer1)

¡© {

¡  timerclear(& (timer1->it_interval));

¡-¡ timer1->it_value.tv_sec = 2;

¡-¢ timer1->it_value.tv_usec = 0;

¡ª£ timer1->it_interval.tv_sec = 0;

¡-¤ timer1->it_interval.tv_usec = 0;

¡¥

¡¦ if (setitimer(ITIMER_REAL, timer1, NULL) != 0)

¡-§ {

¡ ¨

perror ("fils lancement timer" );

¢© }

¢  }

¢-¡

¢-¢ void handler (int iSig)

¢ª£ {

¢-¤ if (iSig == SIGUSR1)

¢¥ {

¢¦ printf ("SIGUSR1\n");

¢-§ TimerFils(&timer);

¢ ¨

}

£© if (iSig == SIGUSR2)

£2  {

£­¡ printf ("SIGUSR2\n");

£­¢ }

£-£ if (iSig == SIGALRM)

£­¤ {

£2¥ printf ("SIGALRM %d\n", getpid());

£2¦ }

(4)

£­§ }

£ ¨

¤©

¤  void TimerPere(Timer * timer)

¤-¡ {

¤-¢ timerclear(& (timer->it_interval));

¤ª£ timer->it_value.tv_sec = 3;

¤-¤ timer->it_value.tv_usec = 0;

¤¥ timer->it_interval.tv_sec = 3;

¤¦ timer->it_interval.tv_usec = 0;

¤-§

¤ ¨

if (setitimer(ITIMER_REAL, timer, NULL) != 0)

¥ª© {

¥-  perror ("fils lancement timer" );

¥$¡ }

¥$¢ }

¥«£ int main (int argc, char **argv)

¥$¤ {

¥-¥ int i;

¥-¦ pid_t pid;

¥$§ // int fils;

¥¨

¦ª©

¦- 

¦$¡

¦$¢ struct sigaction action;

¦«£

¦$¤ signal (SIGALRM, handler);

¦-¥

¦-¦ if ((pid = fork())< 0)

¦$§ {

¦¨

perror ("fork");

§© exit (1);

§  }

§-¡

§-¢ if (pid == 0)

§ª£ {

§-¤ printf("fils - debut\n");

§¥ signal (SIGUSR1, handler);

§¦ /* fils */

§-§ TimerFils(&timer);

§ ¨

while (1)

¨©

{

¨ 

pause();

¨¡

printf("fils - top\n");

¨¢

}

¨£

}

¨¤

else

¨¥

{

¨¦

i = 0;

¨§

printf("pere - debut\n");

¨-¨

TimerPere(&timer);

 ª©-©

while (i++<3)

 ª©­ 

{

(5)

 ª©¿¡

pause();

 ª©¿¢

kill (pid, SIGUSR1);

 ª©$£

}

 ª©¿¤

printf("pere - top\n");

 ª©­¥

 ª©­¦

kill (pid, SIGKILL);

 ª©¿§

while (wait(NULL)>0)

 ª©

¨

;

 - ª©

printf ("bye\n");

 - - 

// kill (pid, SIGKILL);

 - $¡

exit(0);

 - $¢

}

 - «£

 - $¤

/*

 - -¥

return(0);*/

 - -¦

}

gihDjkZlnmlojÁÀ r;Âuwymzm{(´“wymPvÃ|t¶­ƒvÄwGm·¸jk

„…) * ›Å† 2&0‡ 201ˆ13›46"5)Ɖ’"*Š¼'—›‰"5‚)&†*›);46›"*"**2š2 ‚Ž) 2¹‘03ʼn’)Œ* ŽŠ¼'—& 2246"

2"**2š2 ‚\ 13*0œ"*‘‰’"*3† 2˜*63"†’™ ›ˆ"*›†’™ ›šÇD)Œ›Ÿ\"¿#) Å)›46›"~‰"5‚\Ž) 2¹‚’x"*~‰’)Œ* ŽŠ

'—& 2246—#"Ȉ‰¿œ*"Ȇ 2˜6"*“‰"5!!"*“‰"5!†’ 13!Ÿ3&0†’™ P“25 0‰’)Œ* ŽŠ

Références

Documents relatifs

-&gt; Mise en place des patterns, en dur (10 neurones, 1pattern) -&gt; Calcul des poids, à partir des patterns (NB_PATTERNS) -&gt; Algorithme de fonctionnement, critère d'arret MAX

[r]

[r]

[r]

[r]

[r]

[r]

[r]