Thread: Unix processes

  1. #1

    Unix processes

    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.

  2. #2
    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?

    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 05-27-2009, 12:26 PM
  2. How to program in unix
    By Cpro in forum Linux Programming
    Replies: 21
    Last Post: 02-12-2008, 10:54 AM
  3. Setting up a Unix box
    By @nthony in forum Tech Board
    Replies: 6
    Last Post: 07-22-2007, 10:22 PM
  4. binary tree of processes
    By gregulator in forum C Programming
    Replies: 1
    Last Post: 02-28-2005, 12:59 AM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM