Thread: Linux IPC - reading/writing files, getting garbage

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    Linux IPC - reading/writing files, getting garbage

    thanks, I think I have it from here
    Last edited by kbfirebreather; 02-01-2009 at 08:32 PM. Reason: satisfied

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Your help message says "filename <input> <output>", but you read from argv[2] and sent to argv[1]?

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    When you execute the program, in my case I would do..

    Code:
    cse473-ipc inputfile outputfile
    the input file gets sent to send_file, and the output file gets sent to rcv_file

    is that what you meant? and those are called from inside main, between the respective parent/child
    Last edited by kbfirebreather; 02-01-2009 at 02:10 PM. Reason: adding some stuff

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Yes, sorry, I was reading top-down but missed the fork.

    Well, ^A is the character with value 1, which means instead of printing text, you're printing 1. You probably already knew that. Maybe you should check to see whether you're sending 1's as well. I don't see buf getting null-terminated in readline, which makes fprintf an unpleasant sort of thing.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    Well I think my problem is in rcv_file, but I feel like I'm not handling it correctly. When I run the program it always tells me that "rcv_file failed" which is because rcv_file is returning -1, but I'm not to sure why this is happening or how to get around it.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    msgrcv sets errno -- so do a perror, as in
    Code:
    perror("type 2");
    which will print the type 2 also -- and see what it says.

    It also may not hurt to use MTYPE and MEND instead of the magic numbers 1 and 2 (supposing that's what they are).

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    well I believe I am using MTYPE and MEND correct? In send file, when we get to eof that means that the last message is being sent, so when c==1 (eof), i set the .type to MEND, then in rcv file I have to check for the last message which I think is part of my problem.


    And you're saying use perror when msgrcv fails? I have 2 msgrcv's in the while loop to try and test for MEND, which one would get the perror?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Any of them that fails -- but I had in mind the one where it returns -1.

    You are not receiving any messages of MTYPE and MEND. (Those symbols do not appear in your rcvmsg function at all.) You are receiving messages of type 1 and 2. Those very well may be the same thing -- those are the same thing according to the defines -- but use the defines so that we don't confuse ourselves.

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by kbfirebreather View Post
    well I believe I am using MTYPE and MEND correct?
    On the receiving side as well?

    in your read_line function c should be declared as int
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    Well the receiving side reads the message which should have the type in the rcvbuf struct that's passed through the function. which is where you have to detect for the last message which is one thing I don't think my code does correctly.

    It's in the while loop.

    @ tabstop

    I see now, you mean at where it does rcvbuf.type == 2, use MEND instead.

    I'm gonna edit my post and update my code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading/Writing Excel Files
    By milwayh in forum C Programming
    Replies: 4
    Last Post: 11-09-2008, 01:10 PM
  2. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 02:51 PM
  3. OLE2 files in Linux
    By sennaspy in forum Linux Programming
    Replies: 0
    Last Post: 07-06-2002, 10:28 AM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. reinserting htm files into chm help files
    By verb in forum Windows Programming
    Replies: 0
    Last Post: 02-15-2002, 09:35 AM