#include <unistd.
h>
#include <sys/types.h>
#include <errno.h>
#include <time.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
/*struct tm
* {
* int tm_sec; Seconds. [0-60] (1 leap second)
* int tm_min; Minutes. [0-59]
* int tm_hour; Hours. [0-23]
* int tm_mday; Day. [1-31]
* int tm_mon; Month. [0-11]
* int tm_year; Year - 1900.
* int tm_wday; Day of week. [0-6]
* int tm_yday; Days in year.[0-365]
* int tm_isdst; DST. [-1/0/1]
*
* # ifdef __USE_MISC
* long int tm_gmtoff; Seconds east of UTC.
* const char *tm_zone; Timezone abbreviation.
* # else
* long int __tm_gmtoff; Seconds east of UTC.
* const char *__tm_zone; Timezone abbreviation.
* # endif
* };
* */
struct tm t;
int var_glb; /* variable globale */
void affiche_dh(char ch)
{
struct tm *tn ;
char *
mois[12]={"Jan","Fev","Mar","Avr","Mai","Jun","Jul","Aout","Sep","Oct","Nov","Dec"}
;
char * jour[7]={"Dim","Lun","Mar","Mer","Jeu","Ven","Sam"};
/* lire l'heure courante */
time_t now = time (NULL);
printf(" Il fait %d sec depuis le 1/1/1970 a minuit\n\n",now);
/* la convertir en heure locale */
tn=(struct tm *) malloc(sizeof(struct tm));
tn= localtime (&now);
printf("Fin du processus %c le %s. %d %s ",ch,jour[tn->tm_wday],tn-
>tm_mday,mois[tn->tm_mon]);
printf("%d:%d:%d ", tn->tm_hour,tn->tm_min,tn->tm_sec);
printf("%s %d\n",tn->tm_zone,tn->tm_year+1900);
int main(void)
{
int pidfils;
int var_lcl = 0; // Variable locale
system("clear");
pidfils = fork();
switch (pidfils)
{
case -1:
// Echec de fork
printf("\n Fork a echoue !!!!!!\n"); return 1;
case 0: // Processus fils
var_lcl++; var_glb++;
printf("\n Processus fils:%d: var_lcl = [%d], var_glb = [%d]\n",
getpid(), var_lcl, var_glb);
affiche_dh('F');
break;
default: //Processus Parent
var_lcl = 10; var_glb = 20;
printf("\n Processus Parent :%d: var_lcl = [%d], var_glb = [%d]\n",
getpid(), var_lcl, var_glb);
sleep(5);
affiche_dh('P');
}
printf("Fin du programme \n");return 0;
}
int var_lcl = 0; // Variable locale
system("clear");
pidfils = fork();