|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Oct 1999
Città: Milano
Messaggi: 531
|
ipc system V
salve ragazzi....sono proprio alle prime armi...vorrei sapere perchè non mi funziona questo semplice programmino che manda un messaggio tramite ipc ad una coda da me creata...
in particolare MSG_W non viene riconosciuto... #include <stdio.h> #include <sys/types.h> #include <sys/msg.h> #include <string.h> int main(int argc, char **argv) { int mquid,key; size_t len; long type; struct msgbuf *ptr; if (argc!=4) { printf("inserire pathname,tipo messaggio, messaggio\n"); exit(1); } len=length(argv[3]); type=atoi(argv[2]); if ((ptr = (struct msgbuf *) calloc(sizeof(long)+len,sizeof(char)))==NULL) { printf("errore nell'allocazione di memoria di ptr\n"); exit(-1);} ptr->mtype=type; strcpy(argv[3],ptr->mtext); if ((key=ftok(argv[1],1))==-1) {printf("errore nella ftok ora esco!\n"); exit(-1); } if ((mquid=msgget(key,666))==-1) {printf("errore nella msgget ora esco!\n"); exit(-1); } if (msgsnd(mquid,ptr,len,0)==-1) { printf("errore nel messaggio \n"); exit(-1);} exit(0); } mi da anche errori sul puntatore.... c è qualcuno che può aiutarmi?
__________________
Vintage signature: Abit nf7-s, Xp 2500+@2300mhz, 256 mb 418mhz cas2, geforce fx5700,S-ATA 160 Maxtor,Lg gsa 4120b...prima..ma ora..DELL INSPIRON 6400, ATI X1300... |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Oct 2004
Città: Acireale
Messaggi: 447
|
Ciao,
non ne capisco molto di ipc, ma guardando il codice ho notato che c'è un errore ( almeno credo ) su questa istruzione : Codice PHP:
Credo che hai invertito i parametri. La soluzione corretta dovrebbe essere : Codice PHP:
Ciao. |
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Roma
Messaggi: 15625
|
Ci sono alcune imprecisioni in ordine sparso; un esempio funzionante vale più di tante parole:
Codice:
#ifndef _GNU_SOURCE
#warning devi compilare con -D_GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int mquid;
key_t key;
size_t len;
long type;
struct msgbuf *ptr;
size_t ret;
if(argc!=4) {
printf("inserire pathname,tipo messaggio, messaggio\n");
exit(1);
}
len=strlen(argv[3])+1;
type=atoi(argv[2]);
if ((ptr = (struct msgbuf *) calloc(sizeof(long)+len,sizeof(char)))==NULL) {
printf("errore nell'allocazione di memoria di ptr\n");
exit(-1);
}
ptr->mtype=type;
strcpy(ptr->mtext, argv[3]);
if ((key=ftok(argv[1],1))==-1) {
perror("ftok");
exit(-1);
}
/* NB 0666 e' ottale e sono i permission bit */
if ((mquid=msgget(key,0666|IPC_CREAT))==-1) {
perror("msgget");
exit(-1);
}
if (msgsnd(mquid,ptr,len,0)==-1) {
perror("msgsnd");
exit(-1);
} else printf("Inviato: %s\n", mquid->mtext);
bzero(ptr, sizeof(long)+len);
ret = msgrcv(mquid, ptr, len, type, IPC_NOWAIT);
if(ret<0) perror("msgrcv");
else printf("ricevuto: %s\n", ptr->mtext);
return 0;
}
__________________
0: or %edi, %ecx; adc %eax, (%edx); popf; je 0b-22; pop %ebx; fadds 0x56(%ecx); lds 0x56(%ebx), %esp; mov %al, %al andeqs pc, r1, #147456; blpl 0xff8dd280; ldrgtb r4, [r6, #-472]; addgt r5, r8, r3, ror #12 |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 1999
Città: Milano
Messaggi: 531
|
grande
grazie!!
__________________
Vintage signature: Abit nf7-s, Xp 2500+@2300mhz, 256 mb 418mhz cas2, geforce fx5700,S-ATA 160 Maxtor,Lg gsa 4120b...prima..ma ora..DELL INSPIRON 6400, ATI X1300... |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 12:24.



















