"debut TD0"
This commit is contained in:
37
2019-2020/S3T_TP_06_IPC/Squelettes/s_critique.c
Normal file
37
2019-2020/S3T_TP_06_IPC/Squelettes/s_critique.c
Normal file
@@ -0,0 +1,37 @@
|
||||
///***************************************************/
|
||||
///* s_critique : Ce programme illustre le blocage */
|
||||
///* du partage de temps de LINUX avec un semaphore. */
|
||||
///***************************************************/
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
void imprimer (int unNombre, char unCar)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<unNombre; i++) printf ("%c", unCar);
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/// FINIR ///
|
||||
|
||||
int nb, res;
|
||||
assert (argc == 2);
|
||||
nb = atoi (argv[1]);
|
||||
res = fork();
|
||||
if (res == -1)
|
||||
{
|
||||
perror ("fork");
|
||||
exit (1);
|
||||
}
|
||||
if (res == 0)
|
||||
{
|
||||
imprimer (nb, '/');
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
imprimer (nb, '*');
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user