In this code below (server), I need to be able to receive the client’s query’s, insert them in the FCFS queue and, at the same time, I need those query’s to be executed by the server.
I know the code below doesn’t do what I need, and I’m out of the ideas how to do so. I can’t use semaphores, multi-threading etc.. I’m only allowed to use fork’s and pipe’s, if necessary.
int fork_geral;
fork_geral = fork();
if (fork_geral == -1) {
perror("fork");
return 1;
}
//son
if (fork_geral == 0) {
while (1){
handleQueue(queue, argv[1], server_output_info); //will execute the first query in the queue
}
_exit(0);
} else {
while(1) {
while ((bytes_read = read(fd_server, &toRead, sizeof(Msg))) > 0) {
enQueue(queue, toRead);
//send message to the client that the tasked has been received by the server
sprintf(toRead.response, "TASK %d Receivedn", fila->tasks++);
int fd_client = open(toRead.pid_path, O_WRONLY);
if (fd_client == -1) {
perror("open");
return 1;
}
write(fd_client, &toRead, sizeof(toRead));
close(fd_client);
}
}
}
I’ve already tried to make the server request the son process if he is available to handle a queue,
if so we would execute. I used two pipe’s in this solution but it wasn’t working.