Ajout de fichiers
This commit is contained in:
parent
1f0a8d59f7
commit
667f0aef08
BIN
C_Language/TP_SYS/Exemple_curses/a.out
Executable file
BIN
C_Language/TP_SYS/Exemple_curses/a.out
Executable file
Binary file not shown.
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses
Executable file
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses
Executable file
Binary file not shown.
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses.doc
Normal file
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses.doc
Normal file
Binary file not shown.
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses.pdf
Normal file
BIN
C_Language/TP_SYS/Exemple_curses/essaiCurses.pdf
Normal file
Binary file not shown.
89
C_Language/TP_SYS/Exemple_curses/essaicurses.c
Normal file
89
C_Language/TP_SYS/Exemple_curses/essaicurses.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* RSc
|
||||
* essaicurses.c :
|
||||
* Illustration de l'utilisation de curses pour creer deux fenetres
|
||||
* avec un cadre.
|
||||
*/
|
||||
|
||||
#include <curses.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*------------------------------------------------------------------
|
||||
*
|
||||
* creation_fenetre() : cree une fenetre de dialogue avec un cadre
|
||||
* sur n lignes debutant a la ligne d et comportant
|
||||
* le texte t centre sur le bord superieur du cadre
|
||||
* La fenetre occupe toutes les colonnes disponibles (COLS)
|
||||
* ENTREE:
|
||||
* n: nombre de lignes du cadre
|
||||
* d: ligne debut du cadre
|
||||
* t: texte affiche dans le haut du cadre
|
||||
* RESULTAT:
|
||||
* un pointeur sur la fenetre de dialogue creee
|
||||
*
|
||||
* REMARQUES:
|
||||
* - Afin de dessiner un cadre, une fenetre speciale (cadre)
|
||||
* est creee et la fonction box() est appelee pour cette fenetre.
|
||||
* - La fenetre de dialogue (w) est creee a l'interieur du cadre.
|
||||
* - La fonction newwin() admet 4 parametres :
|
||||
* - le nombre de lignes et le nombre de colonnes
|
||||
* - la ligne debut et la colonne debut
|
||||
*-------------------------------------------------------------------*/
|
||||
|
||||
WINDOW *creation_fenetre(int n,int d,char *t)
|
||||
{
|
||||
WINDOW *cadre ; /* la fenetre pour le cadre */
|
||||
WINDOW *w ; /* la fenetre de dialogue */
|
||||
|
||||
/* creation du cadre */
|
||||
|
||||
cadre= newwin(n,COLS,d,0) ;
|
||||
box(cadre,0,0) ;
|
||||
mvwprintw(cadre,0,COLS/2-strlen(t)/2,t) ;
|
||||
wrefresh(cadre) ;
|
||||
|
||||
/* creation de la fenetre de dialogue */
|
||||
|
||||
w= newwin(n-2,COLS-2,d+1,1) ;
|
||||
idlok(w,TRUE) ;
|
||||
scrollok(w,TRUE) ; /* mise en place du defilement (scrolling) */
|
||||
wclear(w) ;
|
||||
wrefresh(w) ;
|
||||
return w ;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
main()
|
||||
{
|
||||
const char CTRL_D = 4 ;
|
||||
|
||||
WINDOW *f_haut, *f_bas ; /* les 2 fenetres de dialogue */
|
||||
WINDOW *w ;
|
||||
char c ;
|
||||
int i ;
|
||||
|
||||
initscr() ; /* initialisation (obligatoire) de curses */
|
||||
noecho() ; /* suppression de l'echo des caracteres tapes*/
|
||||
cbreak() ; /* lecture non bufferisee */
|
||||
|
||||
/* creation des cadres et des fenetres de dialogue */
|
||||
|
||||
f_haut= creation_fenetre(LINES/2,0,"EMISSION") ;
|
||||
f_bas = creation_fenetre(LINES/2,LINES/2,"RECEPTION") ;
|
||||
|
||||
/* lecture et affichage des caracteres */
|
||||
|
||||
while (( c= wgetch(f_bas)) != CTRL_D)
|
||||
{
|
||||
w= islower(c) ? f_haut : f_bas; /* minuscules -> haut; autres -> bas */
|
||||
waddch(w,c) ;
|
||||
wrefresh(w) ;
|
||||
}
|
||||
|
||||
endwin() ; /* remet l'ecran dans son etat initial
|
||||
endwin() est obligatoire pour terminer
|
||||
correctement un pg utilisant curses */
|
||||
}
|
BIN
C_Language/TP_SYS/Exemples_semaphores/a.out
Executable file
BIN
C_Language/TP_SYS/Exemples_semaphores/a.out
Executable file
Binary file not shown.
BIN
C_Language/TP_SYS/Exemples_semaphores/creaZ
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/creaZ
Normal file
Binary file not shown.
52
C_Language/TP_SYS/Exemples_semaphores/creaZ.c
Normal file
52
C_Language/TP_SYS/Exemples_semaphores/creaZ.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* Mecanismes de communication entre processus - IPC */
|
||||
/* Creation d'une zone de mémoire interne partajée (shared memory - shm ) */
|
||||
#include <stdlib.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SHMEM_SIZE 256
|
||||
#define SHMEM_RIGHTS 0x01ff
|
||||
|
||||
/* dimension de la zone : 255 octets */
|
||||
/* droits d'accès dans la zone de mémore partagée: 1ff */
|
||||
/* on nn'utilisera que le premier entier long pour l'exemple */
|
||||
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
|
||||
/* l'identificateur externe (key) de la zone de mémoire partagée
|
||||
est un nombre entier transmis en paramètre par l'utilisateur */
|
||||
|
||||
int ipc_key ;
|
||||
|
||||
int ipc_result ;
|
||||
char * pnl ;
|
||||
int i;
|
||||
|
||||
if (argc<2)
|
||||
exit(1);
|
||||
|
||||
ipc_key = atoi(argv[1]) ;
|
||||
|
||||
/* creation de la zone commune : primitive shmget (....) */
|
||||
|
||||
ipc_result = shmget(ipc_key, SHMEM_SIZE, IPC_CREAT|IPC_EXCL|SHMEM_RIGHTS) ;
|
||||
|
||||
if (ipc_result != -1) {
|
||||
printf(" - Succes !! -\n");
|
||||
|
||||
/* attachement à la zone de mémoire partagée : shmat (....) */
|
||||
|
||||
pnl = (char*)shmat(ipc_result, 0, SHMEM_RIGHTS) ;
|
||||
|
||||
/* initialisation avec 0 de la zone de mémoire partagée */
|
||||
for (i=0;i<SHMEM_SIZE;i++)
|
||||
pnl[i]='\0' ;
|
||||
}
|
||||
else
|
||||
printf(" Erreur :%d \n",ipc_result);
|
||||
|
||||
exit(0) ;
|
||||
}
|
||||
|
BIN
C_Language/TP_SYS/Exemples_semaphores/ecrireZ
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/ecrireZ
Normal file
Binary file not shown.
82
C_Language/TP_SYS/Exemples_semaphores/ecrireZ.c
Normal file
82
C_Language/TP_SYS/Exemples_semaphores/ecrireZ.c
Normal file
@ -0,0 +1,82 @@
|
||||
/* Mecanismes de communication entre processus - IPC */
|
||||
/* Ecriture dans une zone de mémoire partajée */
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SHMEM_SIZE 0xff
|
||||
#define SHMEM_RIGHTS 0x01ff
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
long i , k , temp;
|
||||
long * ptz ;
|
||||
int p1 , p2, p3, p4;
|
||||
int ipc_key, ipc_result ;
|
||||
|
||||
if (argc<2)
|
||||
exit(1) ;
|
||||
|
||||
ipc_key = atoi(argv[1]) ;
|
||||
|
||||
srand ( time(0) ); // initialisation générateur
|
||||
|
||||
ipc_result = shmget(ipc_key, 0 , 0) ; // ouverture mémoire partagée
|
||||
|
||||
ptz = (long *) shmat(ipc_result, 0, SHMEM_RIGHTS) ; // attachement
|
||||
|
||||
if ((p1 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
// while(wait(0) != p1);
|
||||
|
||||
if ((p2 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
// while(wait(0) != p2);
|
||||
|
||||
if ((p3 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
// while(wait(0) != p3);
|
||||
|
||||
if ((p4 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
|
||||
printf("\n Arret processus pid = %d compteur = ( %d )\n\n", getpid(), *ptz) ;
|
||||
|
||||
|
||||
exit(0) ;
|
||||
}
|
BIN
C_Language/TP_SYS/Exemples_semaphores/ecrireZ_Sem
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/ecrireZ_Sem
Normal file
Binary file not shown.
114
C_Language/TP_SYS/Exemples_semaphores/ecrireZ_Sem.c
Normal file
114
C_Language/TP_SYS/Exemples_semaphores/ecrireZ_Sem.c
Normal file
@ -0,0 +1,114 @@
|
||||
/* Mecanismes de communication entre processus - IPC */
|
||||
/* Ecriture dans une zone de mémoire partajée (shared memory - shm ) */
|
||||
|
||||
// VERSION AVEC SEMAPHORE
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SHMEM_SIZE 0xff
|
||||
#define SHMEM_RIGHTS 0x01ff
|
||||
|
||||
void erreur(char *mess);
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
long i , k , temp;
|
||||
long * ptz ;
|
||||
int p1 , p2, p3, p4;
|
||||
int ipc_key, ipc_result ;
|
||||
|
||||
int mutex; // id du semaphore
|
||||
|
||||
|
||||
if (argc<2)
|
||||
exit(1) ;
|
||||
ipc_key = atoi(argv[1]) ;
|
||||
|
||||
|
||||
ipc_result = shmget(ipc_key, 0 , 0) ; // ouverture mémoire partagée
|
||||
ptz = (long *) shmat(ipc_result, 0, SHMEM_RIGHTS) ; // attachement mémoire partagée
|
||||
|
||||
// creation du semaphore mutex
|
||||
|
||||
if((mutex = creat_sem(ipc_key+1,1)) == -1)
|
||||
erreur("erreur creation semaphore");
|
||||
|
||||
if ((p1 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
|
||||
P(mutex); //__________________________
|
||||
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp; ;
|
||||
|
||||
V(mutex); //________________________________
|
||||
|
||||
//(*ptz) ++ ;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
if ((p2 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
|
||||
P(mutex); //__________________________
|
||||
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
|
||||
V(mutex); //________________________________
|
||||
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
if ((p3 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
|
||||
P(mutex); //__________________________
|
||||
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp;
|
||||
|
||||
V(mutex); //________________________________
|
||||
|
||||
//(*ptz) ++ ;
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
if ((p4 = fork()) == 0) {
|
||||
for(i=0;i<10;i++) {
|
||||
|
||||
P(mutex); //__________________________
|
||||
|
||||
temp = * ptz;
|
||||
temp++;
|
||||
sleep( rand() % 2 ); // attente aléatoire
|
||||
*ptz = temp; ;
|
||||
//(*ptz) ++ ;
|
||||
|
||||
V(mutex); //________________________________
|
||||
}
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
// while(wait(0) != -1); si le père attend que tous ses fils soient terminés
|
||||
|
||||
// suppression du semaphore
|
||||
|
||||
//del_sem(mutex);
|
||||
|
||||
printf("\n Arret processus pid = %d compteur ( %d ) \n\n", getpid(), *ptz) ;
|
||||
|
||||
exit(0) ;
|
||||
}
|
BIN
C_Language/TP_SYS/Exemples_semaphores/lireZ
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/lireZ
Normal file
Binary file not shown.
30
C_Language/TP_SYS/Exemples_semaphores/lireZ.c
Normal file
30
C_Language/TP_SYS/Exemples_semaphores/lireZ.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Mecanismes de communication entre processus - IPC */
|
||||
/* Lecture d'une zone de mémoire partagée */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define SHMEM_SIZE 256
|
||||
#define SHMEM_RIGHTS 0x01ff
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
long * ptz ;
|
||||
int ipc_result, ipc_key ;
|
||||
|
||||
if (argc<2)
|
||||
exit(1) ;
|
||||
ipc_key = atoi(argv[1]) ;
|
||||
ipc_result = shmget(ipc_key, 0 , 0) ;
|
||||
ptz = (long *) shmat(ipc_result,0,SHMEM_RIGHTS) ;
|
||||
|
||||
printf("\n Valeur dans la zone partagee : %d \n\n", *ptz) ;
|
||||
exit(0) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
C_Language/TP_SYS/Exemples_semaphores/raZ
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/raZ
Normal file
Binary file not shown.
42
C_Language/TP_SYS/Exemples_semaphores/raZ.c
Normal file
42
C_Language/TP_SYS/Exemples_semaphores/raZ.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* Mecanismes de communication entre processus - IPC */
|
||||
/*
|
||||
/* met a zero l' entier long de la mem par*/
|
||||
#include <stdlib.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SHMEM_RIGHTS 0x01ff
|
||||
|
||||
/* droits d'accès dans la zone de mémore partgée: 1ff */
|
||||
|
||||
|
||||
int main (int argc, char ** argv) {
|
||||
|
||||
/* l'identificateur externe (key) de la zone de mémoire partagée
|
||||
est un nombre entier transmis en paramètre par l'utilisateur */
|
||||
int ipc_key ;
|
||||
|
||||
int ipc_result ;
|
||||
long *ptz;
|
||||
int i;
|
||||
|
||||
if (argc<2)
|
||||
exit(1);
|
||||
|
||||
ipc_key = atoi(argv[1]) ;
|
||||
|
||||
ipc_result = shmget(ipc_key, 0,0);
|
||||
|
||||
if (ipc_result != -1)
|
||||
{
|
||||
printf(" - Succes !! -\n");
|
||||
ptz = (long *) shmat(ipc_result, 0, SHMEM_RIGHTS) ;
|
||||
printf("remise a zero ( %ld ) ", *ptz);
|
||||
*ptz = 0;
|
||||
}
|
||||
else
|
||||
printf(" Erreur :%d \n",ipc_result);
|
||||
exit(0) ;
|
||||
}
|
||||
|
135
C_Language/TP_SYS/Exemples_semaphores/sema.c
Normal file
135
C_Language/TP_SYS/Exemples_semaphores/sema.c
Normal file
@ -0,0 +1,135 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
ushort *array;
|
||||
};
|
||||
|
||||
void erreur(char *s)
|
||||
{
|
||||
if(errno)
|
||||
perror(s);
|
||||
else
|
||||
fprintf(stderr,"%s\n",s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int creat_sem(key_t cle,int val)
|
||||
|
||||
/* creation du semaphore cle ayant comme valeur initiale val
|
||||
retourne un identificateur de semaphore >=0 ou -1 si erreur
|
||||
*/
|
||||
|
||||
{
|
||||
int semid ;
|
||||
|
||||
union semun arg;
|
||||
|
||||
if((semid=semget(cle,1,0666+IPC_CREAT+IPC_EXCL))>= 0)
|
||||
{
|
||||
arg.val=val;
|
||||
if(semctl(semid,0,SETVAL,arg)< 0)
|
||||
semid = -1;
|
||||
}
|
||||
return(semid);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
int del_sem(key_t cle)
|
||||
|
||||
/* destruction du semaphore cle
|
||||
retourne:
|
||||
0 si la destruction du semaphore s est effectuee correctement
|
||||
-1 si erreur
|
||||
*/
|
||||
{
|
||||
int semid;
|
||||
|
||||
if((semid = semget(cle,0,0)) >= 0)
|
||||
semid = semctl(semid,0,IPC_RMID,0);
|
||||
|
||||
if(semid != -1)
|
||||
semid = 0;
|
||||
return semid;
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
|
||||
int chuid_sem(int semid, uid_t uid)
|
||||
|
||||
/* change le owner's user id du semaphore semid en lui donnant la valeur
|
||||
uid
|
||||
retourne 0 si ok
|
||||
-1 si erreur
|
||||
*/
|
||||
{
|
||||
int ret;
|
||||
union semun arg;
|
||||
|
||||
struct semid_ds str_sema;
|
||||
|
||||
arg.buf = &str_sema;
|
||||
|
||||
if((ret = semctl(semid,0,IPC_STAT,arg)) != -1)
|
||||
{
|
||||
str_sema.sem_perm.uid = uid;
|
||||
ret = semctl(semid,0,IPC_SET,arg);
|
||||
}
|
||||
if(ret != -1)
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
|
||||
int open_sem(key_t cle)
|
||||
|
||||
/* recherche le semaphore cle
|
||||
retourne l'identificateur du semaphore >=0 ou -1 si erreur
|
||||
*/
|
||||
{
|
||||
|
||||
return(semget(cle,0,0));
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
|
||||
void P(int semid)
|
||||
|
||||
{
|
||||
struct sembuf psembuf;
|
||||
|
||||
psembuf.sem_op = -1;
|
||||
psembuf.sem_flg = 0;
|
||||
psembuf.sem_num = 0;
|
||||
semop(semid,&psembuf,1);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
void V(int semid)
|
||||
|
||||
{
|
||||
struct sembuf vsembuf;
|
||||
|
||||
vsembuf.sem_op = 1;
|
||||
vsembuf.sem_flg = 0;
|
||||
vsembuf.sem_num = 0;
|
||||
semop(semid,&vsembuf,1);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
6
C_Language/TP_SYS/Exemples_semaphores/sema.h
Normal file
6
C_Language/TP_SYS/Exemples_semaphores/sema.h
Normal file
@ -0,0 +1,6 @@
|
||||
void erreur(char * format, ...);
|
||||
int creat_sem(key_t cle,int val);
|
||||
int del_sem(key_t cle);
|
||||
int open_sem(key_t cle);
|
||||
void P(int semid);
|
||||
void V(int semid);
|
BIN
C_Language/TP_SYS/Exemples_semaphores/sema.o
Normal file
BIN
C_Language/TP_SYS/Exemples_semaphores/sema.o
Normal file
Binary file not shown.
49
C_Language/TP_SYS/FileeDeMessage/msgCons.c
Normal file
49
C_Language/TP_SYS/FileeDeMessage/msgCons.c
Normal file
@ -0,0 +1,49 @@
|
||||
/* travaille avec msgProd.c
|
||||
lit les messages du type donne en parametre sur la ligne de cde
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Defines */
|
||||
#define cle 17
|
||||
|
||||
typedef struct msgbuf_EXD
|
||||
{
|
||||
long type;
|
||||
char text [30];
|
||||
} MSGP;;
|
||||
|
||||
|
||||
/* Global variables */
|
||||
int msqid;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MSGP *m = (MSGP *)malloc (sizeof(MSGP));
|
||||
int type;
|
||||
|
||||
if(argc!=2)
|
||||
{
|
||||
printf ( "usage : msgCons <type> " ) ;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
type = atoi(argv[1]);
|
||||
|
||||
msqid = msgget(cle, 0); // ouverture file message
|
||||
|
||||
// lecture
|
||||
|
||||
|
||||
while(msgrcv(msqid, m, sizeof(MSGP) ,type,1) != -1)
|
||||
{
|
||||
|
||||
// decodage du message
|
||||
|
||||
printf("un message de type %d recu ( %s )\n", m->type, m->text);
|
||||
}
|
||||
return 0;
|
||||
}
|
58
C_Language/TP_SYS/FileeDeMessage/msgProd.c
Normal file
58
C_Language/TP_SYS/FileeDeMessage/msgProd.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* msgProd.c.c
|
||||
|
||||
works with msgCons.c
|
||||
|
||||
Create a message queue et saisit un message et un type et envoie le message
|
||||
*/
|
||||
|
||||
/* Includes */
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Defines */
|
||||
#define cle 17
|
||||
|
||||
/* Global variables */
|
||||
int msqid;
|
||||
|
||||
#define TAILLE_NOM 15
|
||||
|
||||
|
||||
typedef struct msgbuf_EXD
|
||||
{
|
||||
long mtype;
|
||||
char text [30];
|
||||
} MSGP;;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
/* Create the message queue */
|
||||
msqid = msgget(cle, IPC_CREAT|IPC_EXCL|0660);
|
||||
|
||||
/* Fill in the structure */
|
||||
MSGP m1,m2,m3;
|
||||
int type;
|
||||
char mess[20 ];
|
||||
|
||||
|
||||
printf("Taille de la structure MSGP = %d\n ", sizeof(MSGP));
|
||||
|
||||
while( 1)
|
||||
{
|
||||
printf("\nSaisir type destinataire ( 1-5 ) ");
|
||||
scanf("%d",&m1.mtype);
|
||||
printf("\nSaisir un message) ");
|
||||
scanf("%s", m1.text);
|
||||
|
||||
/* Send the message */
|
||||
msgsnd(msqid, &m1, sizeof(MSGP),0);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1 @@
|
||||
ce fichier sert a la fonction ftok pour generer une cle ipc
|
47
C_Language/TP_SYS/FileeDeMessage/test_msgctl.c
Normal file
47
C_Language/TP_SYS/FileeDeMessage/test_msgctl.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* fichier test_msgctl.c */
|
||||
/*
|
||||
* le programme recupere l'identificateur d'une file existante (creee
|
||||
* avec test_msgget.c) et affiche la structure msqid_ds associee a la file
|
||||
*/
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#define CLE 123
|
||||
main()
|
||||
{
|
||||
struct msqid_ds buf ;
|
||||
char *path = "nom2_de_fichier_existant" ;
|
||||
int msqid ;
|
||||
/* recuperation de l'identificateur de la file de messages de cle 123 */
|
||||
if (( msqid = msgget(ftok(path,(key_t)CLE),0)) == -1 ) {
|
||||
perror ("Erreur msgget()") ;
|
||||
exit(1) ;
|
||||
}
|
||||
/* on recupere dans la structure buf les parametres de al file */
|
||||
if (msgctl(msqid,IPC_STAT,&buf) == -1){
|
||||
perror("Erreur msgctl()") ;
|
||||
exit(1) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("id de la file de messages : %d\n",msqid) ;
|
||||
printf("id du proprietaire : %d\n",buf.msg_perm.uid) ;
|
||||
printf("id du groupe du proprietaire : %d\n",buf.msg_perm.gid) ;
|
||||
printf("id du createur : %d\n",buf.msg_perm.cuid) ;
|
||||
printf("id du groupe du createur : %d\n",buf.msg_perm.cgid) ;
|
||||
printf("droits d'acces : %d\n",buf.msg_perm.mode) ;
|
||||
printf("nb courant d'octets dans la file : %d\n",buf.msg_cbytes) ;
|
||||
printf("nb de messages dans la file : %d\n",buf.msg_qnum) ;
|
||||
printf("nb maximal d'octets de la file : %d\n",buf.msg_qbytes) ;
|
||||
printf("pid du dernier ecrivain : %d\n",buf.msg_lspid) ;
|
||||
printf("pid du dernier lecteur : %d\n",buf.msg_lrpid) ;
|
||||
printf("date de la derniere ecriture : %s\n",ctime(&buf.msg_stime)) ;
|
||||
printf("date de la derniere lecture : %s\n",ctime(&buf.msg_rtime)) ;
|
||||
printf("date du dernier changement : %s\n",ctime(&buf.msg_ctime)) ;
|
||||
}
|
||||
}
|
6
C_Language/TP_SYS/constantes.h
Normal file
6
C_Language/TP_SYS/constantes.h
Normal file
@ -0,0 +1,6 @@
|
||||
#define NPLEIN 1
|
||||
#define NVIDE 2
|
||||
#define MUTEX_1 3
|
||||
#define MUTEX_2 4
|
||||
#define MAX_PROD 5 // Maximum de producteurs
|
||||
#define MAX_BUF 100 // Taille maximale du buffer
|
BIN
C_Language/TP_SYS/essaiCurses.pdf
Normal file
BIN
C_Language/TP_SYS/essaiCurses.pdf
Normal file
Binary file not shown.
BIN
C_Language/TP_SYS/manuel_2009.pdf
Normal file
BIN
C_Language/TP_SYS/manuel_2009.pdf
Normal file
Binary file not shown.
2
C_Language/TP_SYS/tp_sema/Makefile
Normal file
2
C_Language/TP_SYS/tp_sema/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
CC=gcc
|
||||
|
113
C_Language/TP_SYS/tp_sema/sema.c
Normal file
113
C_Language/TP_SYS/tp_sema/sema.c
Normal file
@ -0,0 +1,113 @@
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
|
||||
/*void erreurMes(char * format, ...)
|
||||
{
|
||||
char texte[200];
|
||||
va_list liste_arguments;
|
||||
|
||||
va_start(liste_arguments,format);
|
||||
|
||||
vsnprintf(texte,200,format,liste_arguments);
|
||||
|
||||
va_end(liste_arguments);
|
||||
|
||||
if(errno)
|
||||
perror(texte);
|
||||
else
|
||||
fprintf(stderr,texte);
|
||||
exit(1);
|
||||
}
|
||||
*/
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
int creat_sem(key_t cle,int val)
|
||||
|
||||
/* creation du semaphore cle ayant comme valeur initiale val
|
||||
retourne un identificateur de semaphore >=0 ou -1 si erreur
|
||||
*/
|
||||
|
||||
{
|
||||
int semid;
|
||||
|
||||
union semun{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
ushort *array;
|
||||
} arg;
|
||||
|
||||
if((semid=semget(cle,1,0666+IPC_CREAT+IPC_EXCL))>= 0)
|
||||
{
|
||||
arg.val=val;
|
||||
if(semctl(semid,0,SETVAL,arg)< 0)
|
||||
semid = -1;
|
||||
}
|
||||
return(semid);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
||||
int del_sem(key_t cle)
|
||||
|
||||
/* destruction du semaphore cle
|
||||
retourne:
|
||||
0 si la destruction du semaphore s est effectuee correctement
|
||||
-1 si erreur
|
||||
*/
|
||||
{
|
||||
|
||||
return(semctl((semget(cle,0,0)),0,IPC_RMID,0));
|
||||
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------*/
|
||||
|
||||
int open_sem(key_t cle)
|
||||
|
||||
/* recherche le semaphore cle
|
||||
retourne l'identificateur du semaphore >=0 ou -1 si erreur
|
||||
*/
|
||||
{
|
||||
|
||||
return(semget(cle,0,0));
|
||||
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
|
||||
void P(int semid)
|
||||
|
||||
{
|
||||
struct sembuf psembuf;
|
||||
|
||||
psembuf.sem_op = -1;
|
||||
psembuf.sem_flg = 0;
|
||||
psembuf.sem_num = 0;
|
||||
semop(semid,&psembuf,1);
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
void V(int semid)
|
||||
|
||||
{
|
||||
struct sembuf vsembuf;
|
||||
|
||||
vsembuf.sem_op = 1;
|
||||
vsembuf.sem_flg = 0;
|
||||
vsembuf.sem_num = 0;
|
||||
semop(semid,&vsembuf,1);
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
|
7
C_Language/TP_SYS/tp_sema/sema.h
Normal file
7
C_Language/TP_SYS/tp_sema/sema.h
Normal file
@ -0,0 +1,7 @@
|
||||
void erreur(char *s);
|
||||
int creat_sem(key_t cle,ushort val);
|
||||
int del_sem(key_t cle);
|
||||
int open_sem(key_t cle);
|
||||
void P(int semid);
|
||||
void V(int semid);
|
||||
|
BIN
C_Language/TP_SYS/wtest6.c.pdf
Normal file
BIN
C_Language/TP_SYS/wtest6.c.pdf
Normal file
Binary file not shown.
@ -1,14 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main( int argc, char **argv, char **envp)
|
||||
{
|
||||
// I will display all the environment variables
|
||||
while(*envp != NULL)
|
||||
{
|
||||
printf("%s\n", *envp);
|
||||
*envp++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user