Note that there are some explanatory texts on larger screens.

plurals
  1. PORun multiple process server before client
    primarykey
    data
    text
    <p>I am still working on the same homework of Operating System course. Now , here is my question (Firstly, I am rewriting the HW's content): Two programs will be implemented : a client program "get" and a server program called "iserv". A client will ask the server to retrieve and sent all integers in a certain range. The server will be a multi-process program. It will create child processes to handle requests coming from clients. POSIX message queues will be used. Here my iserv.c (server program)</p> <pre><code>struct item /*struct for client requests to the server*/ { int maxvalue; int minvalue; char *queuename; }; int main(int argc , char *argv[]) { pid_t apid1; FILE *fp; mqd_t mq; const char *msgqueue = "/serverqueue"; int oflag = (O_RDWR|O_CREAT); mode_t mode = (S_IRUSR|S_IWUSR); if(argc != 3) { printf("wrong number of arguments"); exit(1); } //create server message queue mq = mq_open(msgqueue ,oflag , mode , NULL); if(mq==-1) { perror("can not open msg queue\n"); exit(1); } printf("mq opened , mq id = %d\n" , (int) mq); //******get the maxvalue and minvalue******* mq_getattr(mq , &amp;attr); printf("mq maximum msgsize = %d\n" , (int) attr.mq_msgsize); /*allocate large enough space for the buffer*/ buflen = attr.mq_msgsize; bufptr = (char *)malloc(buflen); n = mq_receive(mq , (char *)bufptr , buflen , NULL); if(n == -1) { perror("mq_receive failed\n"); exit(1); } itemptr = (struct item *) bufptr; printf("min value = %d\n" , itemptr-&gt;minvalue); printf("max value = %d\n" , itemptr-&gt;maxvalue); fprintf(stderr , "queue name = %s\n" , itemptr-&gt;queuename); free(bufptr); mq_close(mq); mq_unlink(msgqueue); return 0; } </code></pre> <p>and get.c(client program)</p> <pre><code>struct item /*struct for client requests to the server*/ { int maxvalue; int minvalue; char *queuename; }; int main(int argc , char *argv[]) { FILE *file; mqd_t mq; mqd_t mq2; const char *msgqueue = "/serverqueue"; int oflag = (O_RDWR|O_CREAT); mode_t mode = (S_IRUSR|S_IWUSR); struct mq_attr *attr = NULL; struct item item; //for serverqueue int n; if(argc != 5) { printf("wrong number of arguments"); exit(1); mq = mq_open(msgqueue ,oflag , mode , attr); if(mq==-1) { perror("can not open msg queue\n"); exit(1); } printf("mq opened , mq id = %d\n" , (int) mq); //send max - min values and the client message queue name to the serverqueue as a request while(1) { item.maxvalue = atoi(argv[3]); item.minvalue = atoi(argv[2]); item.queuename = clientqueue; n = mq_send(mq , (char *) &amp;item , sizeof(item) , 0); if(n==-1) { perror("mq_send failed\n"); exit(1); } else { printf("mq_send success , item size = %d\n" , sizeof(struct item)); printf("%d" , item.maxvalue); printf("%d" , item.minvalue); printf("\n" , item.queuename); } } mq_close(mq); mq_unlink(msgqueue); return 0; } </code></pre> <p>Makefile:</p> <pre><code>all: iserv get iserv: iserv.c gcc -g -Wall -o iserv iserv.c -lrt get: get.c gcc -g -Wall -o get get.c -lrt clean: rm -fr *o iserv get </code></pre> <p>Now , my first question is even if I remove the message queue by using mq_close and mq_unlink , when I want to run these two programs terminal says that : nothing do be done for 'all'. I need to remove something else to rerun these two programs without closing or deleting anything with hand. What is this??</p> <p>Second question is that <code>char *queuename;</code> in the message response cannot be taken by the server as a name. It prints out something silly on the terminal , how can I pass the string queuename to the server in this message response??</p> <p>Please help me , homework due date is close I need to solve these problems , thank you for all help !!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload