Hi. If a linux process issues a blocking command like reading from a socket, which blocks indefinitely, can a context switch still occur while the command is waiting? In other words, is just THAT process blocked, or are all processes blocked?
I want to make a network messaging program that, after making a connection, forks into to 2 parts: one to read messages from the other side and one to fget input from the keyboard and send it. The problem is, both recv and fgets block, so once either process got the CPU, it would not give the other one a turn until recv() or fgets() returned (if these indeed block all processes). The result would be that the processes would take turns, and there would be virtually no concurrent execution at all, which defeats the purpose of using processes. The users would have to take turns sending messages back and forth, which is not what I want.
Thanks in advance.
Thanks! That's pretty much exactly the code I needed.
I only encountered one problem. The code appears to be written for a program acting as a client, since it uses connect() to establish the connection, so I made a companion program that acts as a server, and replaced the connect() with appropriate calls to bind(), listen(), and accept(). The problem is when I run the client and server versions, I can only pass messages from the client version to the server version. When I try to send a message from the server back to the client, the program quits and says "Broken pipe". Do you have any idea what I can do about this?