Stack Smashing detected in IPC

program 1 to send message:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<sys/msg.h>
#include<sys/ipc.h>
#include<cstring>
#include "globals.h"


using namespace std;


int main(){


    char name[80];
    int msgid;
    MSG message;

    msgid=msgget(MSGQ_ID, 0666|IPC_CREAT);

    cout<<"Enter a string: ";
    cin.getline(name, 80);

    if(msgid>=0){

        strcpy(message.msg,name);
        message.type=1;
        int ret= msgsnd(msgid, &message, sizeof(message), 0);

    }
    return 0;
}

programe 2 to rec message //here I get the error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include "globals.h"
#include<sys/msg.h>
#include<sys/ipc.h>
#include<cstring>

using namespace std;

int main(){

    MSG rec;
    int msgid;
    msgid=msgget(MSGQ_ID, 0);
    if(msgid>=0){

        int ret=msgrcv(msgid,&rec, sizeof(rec),1,0);
        cout<<"Recieved "<<rec.msg<<endl;;

       

        //msgctl(msgid, IPC_RMID, NULL);
}
    return 0;
}

Last edited on
You should read the documentation for the functions you're using. Line 16 in the second snippet is incorrect.
I am following the examples from handouts to solve new problems,
Topic archived. No new replies allowed.