Skip to content

Commit d64b77c

Browse files
authored
Add files via upload
1 parent 0c21d7a commit d64b77c

File tree

10 files changed

+148
-0
lines changed

10 files changed

+148
-0
lines changed

Message Queue/Receive/Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
TARGET = message_queue_receive
2+
3+
CC = gcc
4+
CFLAGS = -g -Wall
5+
6+
SRC = src
7+
SRCS = $(wildcard $(SRC)/*.c)
8+
9+
OBJ = obj
10+
OBJS = $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
11+
12+
INC = inc
13+
INCLUDES = -I$(INC)
14+
15+
BIN_DIR = bin
16+
BIN = $(BIN_DIR)/$(TARGET)
17+
18+
all: $(BIN)
19+
20+
$(BIN): $(OBJS) $(OBJ)
21+
$(CC) $(CFLAGS) $(OBJS) -o $@
22+
23+
$(OBJ)/%.o: $(SRC)/%.c
24+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
25+
26+
$(OBJ):
27+
mkdir -p $@
28+
29+
clean:
30+
rm -rf $(BIN_DIR)/* $(OBJ)/*
31+
32+
edit:
33+
vim -O $(SRC)/*.c $(INC)/*.h
34+
35+
dir:
36+
mkdir inc src obj bin
37+
touch $(INC)/main.h $(SRC)/main.c
38+
39+
create-project:
40+
mkdir $(TARGET)
41+
cp ./Makefile ./$(TARGET)/
42+
43+
delete-project:
44+
rm -rf inc src obj bin
19.4 KB
Binary file not shown.

Message Queue/Receive/inc/main.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <stdio.h>
2+
#include <sys/types.h>
3+
#include <sys/ipc.h>
4+
#include <sys/msg.h>

Message Queue/Receive/obj/main.o

7.02 KB
Binary file not shown.

Message Queue/Receive/src/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include "main.h"
2+
3+
struct msg_buffer {
4+
long msg_type;
5+
char msg_txt[500];
6+
}message;
7+
8+
int main(int argc, char *argv[])
9+
{
10+
key_t key;
11+
int msg_id;
12+
13+
key = ftok("/home/blackally/message_queue/progfile", 65);
14+
15+
msg_id = msgget(key, IPC_CREAT);
16+
17+
msgrcv(msg_id, &message, sizeof(message), 1, 0);
18+
19+
printf("The msg that we have received is : %s\n", message.msg_txt);
20+
21+
msgctl(msg_id, IPC_RMID, NULL);
22+
return 0;
23+
}

Message Queue/Send/Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
TARGET = message_queue_send
2+
3+
CC = gcc
4+
CFLAGS = -g -Wall
5+
6+
SRC = src
7+
SRCS = $(wildcard $(SRC)/*.c)
8+
9+
OBJ = obj
10+
OBJS = $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS))
11+
12+
INC = inc
13+
INCLUDES = -I$(INC)
14+
15+
BIN_DIR = bin
16+
BIN = $(BIN_DIR)/$(TARGET)
17+
18+
all: $(BIN)
19+
20+
$(BIN): $(OBJS) $(OBJ)
21+
$(CC) $(CFLAGS) $(OBJS) -o $@
22+
23+
$(OBJ)/%.o: $(SRC)/%.c
24+
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
25+
26+
$(OBJ):
27+
mkdir -p $@
28+
29+
clean:
30+
rm -rf $(BIN_DIR)/* $(OBJ)/*
31+
32+
edit:
33+
vim -O $(SRC)/*.c $(INC)/*.h
34+
35+
dir:
36+
mkdir inc src obj bin
37+
touch $(INC)/main.h $(SRC)/main.c
38+
39+
create-project:
40+
mkdir $(TARGET)
41+
cp ./Makefile ./$(TARGET)/
42+
43+
delete-project:
44+
rm -rf inc src obj bin
19.4 KB
Binary file not shown.

Message Queue/Send/inc/main.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <stdio.h>
2+
#include <sys/types.h>
3+
#include <sys/ipc.h>
4+
#include <sys/msg.h>

Message Queue/Send/obj/main.o

7.2 KB
Binary file not shown.

Message Queue/Send/src/main.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "main.h"
2+
3+
struct msg_buffer {
4+
long msg_type;
5+
char msg_txt[500];
6+
}message;
7+
8+
int main(int argc, char *argv[])
9+
{
10+
key_t key;
11+
int msg_id;
12+
13+
key = ftok("/home/blackally/message_queue/progfile", 65);
14+
15+
msg_id = msgget(key, 0666| IPC_CREAT);
16+
message.msg_type = 1;
17+
18+
printf("Please write data to send:");
19+
fgets(message.msg_txt, 500, stdin);
20+
21+
msgsnd(msg_id, &message, sizeof(message), 0);
22+
23+
printf("we have sent : %s \n", message.msg_txt);
24+
25+
26+
27+
28+
return 0;
29+
}

0 commit comments

Comments
 (0)