From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,cf7b099c99ee894b X-Google-Attributes: gidfc89c,public X-Google-Thread: f678f,cf7b099c99ee894b X-Google-Attributes: gidf678f,public X-Google-Thread: fee84,cf7b099c99ee894b X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,cf7b099c99ee894b X-Google-Attributes: gid1014db,public From: fred@genesis.demon.co.uk (Lawrence Kirby) Subject: Re: Digital Unix message queue programming problem!! Date: 1997/02/27 Message-ID: <857065180snz@genesis.demon.co.uk>#1/1 X-Deja-AN: 221866881 References: <33162B5F.437B@silicon.net.my> X-Mail2News-User: fred@genesis.demon.co.uk Followup-To: comp.unix.osf.osf1,comp.unix.programmer,comp.unix.osf.misc X-Mail2News-Path: genesis.demon.co.uk Organization: none Reply-To: fred@genesis.demon.co.uk Newsgroups: comp.unix.osf.osf1,comp.unix.programmer,comp.unix.osf.misc,comp.lang.c In article <33162B5F.437B@silicon.net.my> fskok@silicon.net.my "Kok Fock Seng" writes: >Hi out there, > >I am writing a program utilize the message queue (IPC) feature >in Dec Unix. Note that your question was not about the C language so it wasnt' really appropriate to cross-post to comp.lang.c. (Removed from follow-ups) >void main () Since you have cross-posted to comp.lang.c I'd just point out that C defines main as a function returning int. More specifically as either: int main(void) or int main(int argc, char *argv[]) >{ > int messageid; > > m.msgtype = 1L ; > strcpy(m.msgbuf,"This is a test msg!") ; > > if (( messageid = msgget ((key_t)(6000L), IPC_CREAT)) == -1 ) (pretending I'm reading this in comp.unix.programmer) There is a problem here in that you failed to give any read/write permissions on the queue. Check your man page more carefully for what the 2nd argument should be (it is basically a collection of bit flags similar to the 2nd argument of open()) > exit (-1); Why -1? C defines 0, EXIT_SUCCESS and EXIT_FAILURE. Unix essentially takes the lower order 8 bits of the value (i.e. a value 0-255) although some shells may have a weirdness of treating this like a signed char. > fprintf(stderr, "[%d]", messageid); > > if ( msgsnd ( messageid, &m, strlen(m.msgbuf)+1, 0) == -1) > fprintf(stderr, "Test Queue got problem!\n err [%d]", errno); > else fprintf(stderr, "Test Queue OK!\n"); > printf(stderr, "[%d]\n", errno) ; You need to make up your mind whether to printf this to stdout or fprintf it to stderr! :-) -- ----------------------------------------- Lawrence Kirby | fred@genesis.demon.co.uk Wilts, England | 70734.126@compuserve.com -----------------------------------------