798;:<=2>(?A@(BDC!EFGFG=HJIK>MLNBPORQ;:SOTEH3<GF
UDVXWZY\[]^`_
acbdb _e
acbdbcf
gihDjkZlnmlojqp rtsuj!vxwymzzj!{({yj}|~j!{kGloj!{({y~{
) * D 2&0 2011346c"*0),)*4x"5n046"*o6*"c 60n4"5n13&)"*
)2)&01300'x 2&)2c 2"55"*2 2 *"*" 0)*4)&c5"*, 2 2Z&0
6) &5 ","5)&013200 &)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 */
¢¦ 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);*/
§ ¨
}
) * J &0 13134("5)"5c'"5"5) *13 , ® )&&0J 2c.#&0 21*
' "*0) 2D*1 2c2¹2¹.yºP)&6%»)4!./&05 46"*213 ¼&1c "c0 ,"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¦ }
£§ }
£ ¨
¤©
¤ 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)
ª©
{
ª©¿¡
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{(´wymPvÃ|t¶vÄwGm·¸jk
) * Å 2&0 2011346"5)Æ"*¼'"5)&*);46"*"**22 ) 2¹03Å)* ¼'& 2246"
2"**22 \ 13*0"*"*3 2*63" "* ÇD)\"¿#) Å)46"~"5\) 2¹x"*~)*
'& 2246#"È¿*"È 26"*"5!!"*"5! 13!3&0 P25 0)*