I have a server and client application, using IPC queues. The server is (for now) simply sending back the text received from the client. I would like the server to change the letters in the message from lower to upper case. I’m wondering how to achieve it. Do I have to create a pipe? I’m thinking about ‘grabbing’ the text from the received queue, executing the tr command on it and sending back to the client. But if using a pipe, from where do I get the file descriptors? I mean, int fds[2]; and pipe(fds); gives me a pipe, but it’s not working on two char arrays like this:
int fds[2];
pipe(fds);
char a[100];
char b[100];
fds[0] = open(a,O_RDOLNY);
fds[1] = open(b,O_WRONLY);
How can I execute a tr command on a text held by a message queue?
I wouldn’t
forka program for this:More seriously, you should probably use
popenthat automatically (and robustly) forks and uses a pipe to setup aFILE *for you.And then simple
fgetsfrom it (don’t forget topcloseit). Sadly on Linux you can’t write and read to a popened file at the same time (you can on FreeBSD).EDIT
Since this is a homework question (and frankly because I don’t think it’s trivial to get it completely right at this time of night), here is what
popenactually does:FILE *(possibly viafdopen)The last step is really optional as you could always read from the file descriptor directly.