Upload
youssef-ysf
View
221
Download
0
Embed Size (px)
Citation preview
7/25/2019 Pipes Signaux
1/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
3IS - Systme d'exploitation linux-
Signaux et pipes
2010 David Picardontri!utions de " #rnaud $evel% &ica(l &aillard
picard)ensea*+r
7/25/2019 Pipes Signaux
2/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
ommunication entre processus
,ntre un pre et son +ils one de data aprs +or./ .mais sens uniue/ Paramtres aprs exec./
Pipe ,ntre deux processus sans lien
Pipe nomm ic4iers
Problme : solutions trs lentes
7/25/2019 Pipes Signaux
3/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Signaux
&oyen simple de communication entreprocessus
5nrs soit ,xception au cours de l'excution du processus D'origine matrielle " erreur d'adressage% virgule +lottante D'origine logicielle " 6$7-% SI587D% sur commande
7orsu'un processus re9oit un signal Il est dtruit .par d+aut/ :ne routine spciale est excute
7/25/2019 Pipes Signaux
4/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
6ype de signaux#define SIGHUP 1 /* Hangup (POSIX). */
#define SIGINT 2 /* Interrupt (ANSI). */
#define SIGQUIT 3 /* Quit (POSIX). */
#define SIGILL 4 /* Illegal instruction (ANSI). */
#define SIGTRAP 5 /* Trace trap (POSIX). */#define SIGABRT 6 /* Abort (ANSI). */
#define SIGIOT 6 /* IOT trap (4.2 BSD). */
#define SIGBUS 7 /* BUS error (4.2 BSD). */
#define SIGFPE 8 /* Floating-point exception (ANSI). */
#define SIGKILL 9 /* Kill, unblockable (POSIX). */
#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */
#define SIGSEGV 11 /* Segmentation violation (ANSI). */
#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */
#define SIGPIPE 13 /* Broken pipe (POSIX). */
#define SIGALRM 14 /* Alarm clock (POSIX). */
#define SIGTERM 15 /* Termination (ANSI). */#define SIGSTKFLT 16 /* Stack fault. */
#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */
#define SIGCHLD 17 /* Child status has changed (POSIX). */
#define SIGCONT 18 /* Continue (POSIX). */
#define SIGSTOP 19 /* Stop, unblockable (POSIX). */
#define SIGTSTP 20 /* Keyboard stop (POSIX). */
#define SIGTTIN 21 /* Background read from tty (POSIX). */
#define SIGTTOU 22 /* Background write to tty (POSIX). */
#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */
#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */
#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */
#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */
#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */
#define SIGPOLL SIGIO /* Pollable event occurred (System V). */
#define SIGIO 29 /* I/O now possible (4.2 BSD). */
#define SIGPWR 30 /* Power failure restart (System V). */
#define SIGSYS 31 /* Bad system call. */
7/25/2019 Pipes Signaux
5/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
7es signaux ne sont pas desinterruptions ;
7ors d'une interruption% la routine associe estexcute immdiatement
7ors de la rception d'un signal% le code
associ sera excut lorsue le processus auradu temps d'excution disponi!le sur un P:
7es signaux ne sont ps temps r!els "
7/25/2019 Pipes Signaux
6/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
onctionnement par d+aut
7/25/2019 Pipes Signaux
7/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
&ise en place d'un 4andler
Programme
8andler
Signal
7/25/2019 Pipes Signaux
8/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
signal()
#include
void spint(int sig)
{
printf("Recu signal d'interruption %d\n",sig);
}
int main()
{
signal(SIGINT,spint);
pause();
exit(0);
}
7/25/2019 Pipes Signaux
9/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
kill()
#include
void spsig(int sig)
{ printf("Signal %d recu\n",sig); }
int main()
{
int idfils, status;
if (idfils=fork()) { /* pere */
sleep(5);
kill(idfils,SIGUSR1);
wait(&status);
exit(0);
}
else { /* fils */ signal(SIGUSR1,spig);
pause();
exit(1);
}
}
7/25/2019 Pipes Signaux
10/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Signaux temps rel
7a norme posix 1*! impose au moins < signaux dits=temps-rels>
7inux en supporte 32 numrots de 32 .SI5$6&I?/ @3 .SI5$6A/
7es signaux temps-rel n'ont pas de signi+icationprd+inie
7'action par d+aut est de terminer le processus
si des signaux standards et des signaux temps-relsont simultanment en attente pour un processus 7inuxdonne la priorit aux signaux temps-rel
7/25/2019 Pipes Signaux
11/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
aux temps rel ;;;
7e uali+icati+ BBtemps-rel'' est trompeur; #ucune contrainte temporellen'est impose au
niveau de l'ordonnanceur omme pour les signaux standards le signal
sere dlivr un processus uniuement uandcelui-ci sera ordonnanc
7/25/2019 Pipes Signaux
12/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Proprits
Plusieurs instances d'un signal peuvent Ctre empiles./proc/sys/kernel/rtsig-max/ un signal temps-relpeut Ctre envoy par sigqueue()et accompagn d'unparamtre*
:n gestionnaire utilisant l'appel sigaction()peutaccder cette valeur
si plusieurs signaux temps-rel sont envoys ils sontdlivrs en commen9ant par le signal de numro le moins
lev .le signal de plus +ort numro est celui de priorit laplus +ai!le/*
7es signaux temps-rel du mCme type sont dlivrs dansl'ordre o ils ont t mis*
7/25/2019 Pipes Signaux
13/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple de gestionnaire
#include
void gestionnaire(int sig, siginfo_t *info, void *inutile)
{
char *origine;
printf("Reception du signal n %d ", sig); switch ( info->si_code ){
case SI_USER:
printf("envoyau moyen de kill() ou raise() par le processus %ld\n", info->si_pid);
break;
case SI_QUEUE:
printf("envoyau moyen de sigqueue() par le processus %ld avec la valeur %d\n",
(long)info->si_pid, info->si_value.sival_int);
break;
default: printf("\n");
break;
}
}
7/25/2019 Pipes Signaux
14/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple d'utilisation
int main(){
pid_t pid_fils;
switch ( pid_fils = (long)fork() ){
case -1: perror("Erreur lors de fork"); return EXIT_FAILURE;
case 0:
{ sigset_t masque; struct sigaction action;
sigemptyset(&masque);
sigaddset(&masque, SIGUSR1);
sigprocmask(SIG_BLOCK, &masque, NULL); action.sa_sigaction = gestionnaire;
action.sa_mask = masque;
action.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &action, NULL);
sigprocmask(SIG_UNBLOCK, &masque, NULL);
while(1);
}
default: { union sigval val;
val.sival_int = 123;
sigqueue(pid_fils, SIGUSR1, val);
wait(NULL);
}}
return EXIT_SUCCESS;
}
7/25/2019 Pipes Signaux
15/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Pipes
:n pipe est un +ic4ier virtuel .pas stoc sur undisue/
Il possde deux descripteurs " un en lecture et
un en criture 7es descripteurs de +ic4iers tant partags par
un processus pre et son +ils% le pipe permet lacommunication de donnes entre processus
Il +onctionne avec un tampon circulaire
7/25/2019 Pipes Signaux
16/36COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
pipe()
text
data
stac
task_struct
+d1
rEpo
sition
re+F1
i
ptr
+d2
GEp
osition
re+F1
i
ptr
rEpos
GEpos
re+F2
7/25/2019 Pipes Signaux
17/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
pipe()
7e pre crit dans le pipe
7e +ils lit depuis le pipe Hu l'inverse***
7/25/2019 Pipes Signaux
18/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple de code
int main(){
int status,pipedes[2];
char buf[100];
int len;
char *msg="Salut Fred !";
struct stat pipestat;
if (pipe(pipedes)) exit(1);
if (fork()) { /* Code du pere */ write(pipedes[1],msg,strlen(msg));
wait(&status);
return;
}
else { /* Code du fils */
while(len==0) /* Attend que le pipe soit rempli */
{
if (fstat(pipedes[0],&pipestat)) exit(3); len=(int)pipestat.st_size;
}
read(pipedes[0],buf,len);
printf("Mon pere adore l'art de decaler les sons : %s\n",buf);
return;
}
}
7/25/2019 Pipes Signaux
19/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple 2 pipes
int main(){
int status;
char bufp[13];
if (pipe(pipdes1)) exit(1);
if (pipe(pipdes2)) exit(1);
if (fork())
{ /* Fermeture du pipe 0 en
ecriture et 1 en lecture */
close(pipdes1[0]);
close(pipdes2[1]);
write(pipdes1[1],"Salut les process...",21);
read(pipdes2[0],bufp,13);
printf("Pere: %s\n",bufp);
wait(&status);
exit(0); }
else
{
fils();
}
}
int pipdes1[2],pipdes2[2];
void fils()
{
char buff[21];
/* Fermeture du pipe 1 en
ecriture et 0 en lecture */
close(pipdes1[1]);
close(pipdes2[0]);
read(pipdes1[0],buff,21);
printf("fils : %s\n",buff);
write(pipdes2[1],"Message
recu",13);
return;
}
7/25/2019 Pipes Signaux
20/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Pipes nomms
:n +ic4ier spcial est cr .p/ :ne inode est rserve ?'est pas utilis comme un +ic4ier mais comme
un pipe
7/25/2019 Pipes Signaux
21/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple cration et criture
#include
#include
#include
#include
#define NAME_PIPE "./my_pipe"
int main(int ac, char **av)
{ char DATA[32];
int fd;
int pid;
mkfifo(NAME_PIPE, 0666);
fd = open(NAME_PIPE, O_WRONLY);
if (fd == -1)
exit(1);
pid = getpid();
sprintf(DATA, "%i dit hello", pid);
write(fd, DATA, strlen(DATA) + 1);
sleep(5);
return 0;
}
7/25/2019 Pipes Signaux
22/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple ouverture et lecture
#include
#include
#include
#include
#define NAME_PIPE "./my_pipe"
#define BUFFSIZE 1024
int main(int ac, char **av)
{
char sbBuf[BUFFSIZE];
int fd;
int pid;
fd = open(NAME_PIPE, "r");
pid = getpid();
read(fd, sbBuf, BUFFSIZE);
printf("[%i] %s\n", pid, sbBuf);
return 0;
}
7/25/2019 Pipes Signaux
23/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Socets
,xtension des pipes nomms des processusse trouvant sur des mac4ines di++rentes
#pparues en 1
7/25/2019 Pipes Signaux
24/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
ration d'une socet
int socket(int domaine, int type, int protocole)
Domaine de communicartion .IP " #EI?,6%IPv@ " #EI?,6@% :nix " #E:?IA% etc/
6ype de socet SHMES6$,#& .connect/ SH7ED5$#& .non connect/
SHME$#N .!rute/ Protocole .6P " IPP$H6HE6P% etc peut-
Ctre ?:77 et devin par l'HS/
7/25/2019 Pipes Signaux
25/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple#include
int main() {
int sock;
if(( sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf( error socket\n );
return -1;
}
return 0;
}
7/25/2019 Pipes Signaux
26/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Ot serveur
#ttac4ement de la socet une adresseport "bind(int sock, struct sockaddr *a, socklen_t len)
#ttente de connexion .coute/ "
listen(int sock, int nb_file_attente)
7ancement de la routine excuter en cas deconnexion
accept(int sock, struct sockaddr *a, socklen_t *len)
,n gnral% on +or./ 7e pre retourne l'coute
7e +ils e++ectue le traitement
7/25/2019 Pipes Signaux
27/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xempleint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
28/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
rationint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
29/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Init de la struct addrint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
30/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
#ttac4ementint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
31/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
#ttenteint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
32/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
?ouvelle connectionint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
33/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
$etour en attenteint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
34/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
6raitementint main(int argc, char *argv[])
{
int sfd, cfd; struct sockaddr_un my_addr, peer_addr; socklen_t peer_addr_size;
sfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path) - 1);
if (bind(sfd, (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)) == -1)
handle_error( bind );
if (listen(sfd, LISTEN_BACKLOG) == -1)
handle_error( listen );
while(1) {
peer_addr_size = sizeof(struct sockaddr_un);
cfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
if (cfd == -1) handle_error( accept );
if(fork()) { /* pere
close(cfd); continue;
} else { /* fils */
close(sfd); /* code du traitement des donnes */
}
}
}
7/25/2019 Pipes Signaux
35/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
Ot client
int connect(int sock, struct sockaddr *a, int len)
rer la socet avec socet./ Huvrir la connection une adresse port Pas !esoin de !ind./
7/25/2019 Pipes Signaux
36/36
COLE NATIONALE SUPRIEURE DE L'LECTRONI UE ET DE SES APPLICATIONS
,xemple#define MY_SOCK_PATH /tmp/mysock
int main(int argc, char *argv[])
{
int cfd; struct sockaddr_un my_addr;
char buffer[64];
cfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sfd == -1) handle_error( socket );
memset(&my_addr, 0, sizeof(struct sockaddr_un));
my_addr.sun_family = AF_UNIX;
strncpy(my_addr.sun_path, MY_SOCK_PATH, sizeof(my_addr.sun_path)
1);
if(connect(cdf, &my_addr, sizeof(struct sock_addr_un)) < 0) }
handle_error( connect );
}
read(cdf, buffer, 64);
printf( lu : %s\n , buffer);
return 0;
}