LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-15-2015, 12:56 PM   #1
Tala_22
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
Question IPC _synchronization message queue


Hi
i am trying to do c program calculate matrix multiplication that fork 2 child each child calculate two element and send the result via message queue to their parent .
the last printf doesn't appears in output .
any one help me ?

#include<stdio.h>
#include<stdlib.h>
#include<linux/ipc.h>
#include<linux/msg.h>
#include<sys/types.h>
typedef struct mymsgbuf
{
long mtype;
int num,num1,num2,num3;
}mess_t;
int main( int argc,char* argv[])
{
int qid;
key_t msgKey;
pid_t pid;
mess_t buf;
int array1[2][2]={{1,2},{2,2}};
int array2[2][2] ={{3,4},{3,5}};
int val1;

int length;
int cont;
length = sizeof(mess_t) - sizeof(long);


msgKey = (key_t)atoi(argv[1]);
qid=msgget(msgKey,IPC_CREAT|0660);

if(!(pid= fork())){
int val1,val2 =0;
printf ("SON -QID =%d\n",qid);
srand(time(0));

val1 = (1*3)+(2*5);
val2 =(1*4)+(2*5);

buf.mtype=1;
buf.num = val1;
buf.num1 = val2;
msgsnd(qid,&buf,length,0);
printf("\n son-messaged %d\n",buf.num);
printf("\n c[0][1] %d \n",buf.num1);
exit(0);}



else if(!(pid =fork()))

{int val3, val4 =0;
val3 =(2*3)+(2*3);
val4=(2*4)+(2*6);
sleep(10);
buf.mtype = 1;
buf.num2 = val3;
buf.num3 = val4;
sleep(15);
msgsnd(qid,&buf,length,0);
// printf("\n c[1][0]_ch is = %d \n",buf.num3);
sleep(15);
exit(0);

}
else {
wait();
wait();

sleep(30);
msgrcv(qid,&buf,length,1,0);



printf("\n c[0][0] =%d\n",buf.num);
printf("\n c[0][1] =%d",buf.num1);
sleep(30);

msgrcv(qid,&buf,length,1,0);
printf("\n c[1][1] =%d", buf.num2);

msgctl (qid,IPC_RMID,0);

return ;
}}
 
Old 12-15-2015, 07:38 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The way you format your program makes it hard to read. Can you surround it by code tags?

That is:

[code]
your program
[/code]
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux IPC - message queues aryan1 Programming 6 08-03-2009 02:22 AM
Is it possible for me to write in front of queue in case of message queue? hemanthv414 Linux - Newbie 1 11-17-2008 04:40 PM
IPC V message queue --msgsnd() call jasdeep.js Linux - Kernel 1 01-02-2007 06:59 PM
IPC message between process (Sync) davidho3 Linux - Networking 1 07-24-2004 08:20 AM
IPC message between process (Sync) davidho3 Programming 1 07-24-2004 07:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration