Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* #include <cstdlib> */
- #include <iostream>
- #include <cerrno>
- #include <limits>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- using namespace std;
- #define BUFSIZ 512
- struct my_msg_st {
- long int my_msg_type;
- char some_text[BUFSIZ];
- };
- int main(int argc, char** argv)
- {
- int running = 1;
- int msgid;
- struct my_msg_st some_data;
- long int msg_to_receive = 5;
- /* Set up the message queue */
- msgid = msgget((key_t) 1234, 0666 | IPC_CREAT);
- if (msgid == -1) {
- cout << "msgget failed" << endl;
- exit(EXIT_FAILURE);
- }
- /* Retrieve messages from the queue until an "end" is encountered. */
- while (running) {
- // if (msgrcv(msgid, (void *)&some_data, BUFSIZ,
- // msg_to_receive, 0) == -1) {
- // cout << "msgrev failed" << endl;
- //exit(EXIT_FAILURE);
- //}
- // char *args[] = {"/bin/ls", "-1", "/tmp/cs261*"};
- char *args[] = {"/bin/ls"};
- execvp("/bin/ls", args);
- cout << some_data.some_text;
- if (strncmp(some_data.some_text, "end", 3) == 0) {
- running = 0;
- }
- sleep(1);
- }
- if (msgctl(msgid, IPC_RMID, 0) == -1) {
- cout << "msgctl(IPC_RMID) failed" << endl;
- exit(EXIT_FAILURE);
- }
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement