Results 1 to 6 of 6

Thread: Manipulating IPC in C language

  1. #1
    Join Date
    Jun 2009
    Posts
    105

    Manipulating IPC in C language

    I have a TP of C to manipulating IPCs (semaphores, message queues, etc.) One thing before you start it, know that all my processes to compile. I'll spare you the unnecessary details of my TP, the problem is simple:

    I use 2 processes to bind a message queue (= mailbox) so that the latter 2 may eg initially exchange their respective PID. The 1st process sending out his message (message type 1), and the recipient receives it well. The recipient then responds by sending a message queue of its PID (message type 2). But I tried to read this message with several processes, and every block (they are waiting for a message type 2) to order: msgrcv (id_BAL, & message, 100,2,0);
    Each process has the same law as has this message queue: 0666 (read / write);

    I do not understand why they block as if no message of type 2 exist in the queue. Especially when I type the cmd shell ipcs, I see that my message queue contains several messages (in this case here, 2).

    If you have an idea which might come from the worries thank you for telling me, because it's pretty boring

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Manipulating IPC in C language

    System V IPC, it is a long time that nobody uses this API archaic, replaced by the POSIX API for a long time. I can not believe we can still teach this stuff in 2010. Are you really forced to use this API shit?

  3. #3
    Join Date
    Jun 2009
    Posts
    105

    Re: Manipulating IPC in C language

    Yes. Do not ask me why I do not know anything, I thought that was so outdated that it! I just watched, bcp school of engi telecommunications sector (like mine) it teaches. There is probably a good reason!

    Finally in such case thank you for responding. If by chance that studied it all and he knows my answer would be same damn helping

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: Manipulating IPC in C language

    * If one process produces the message and consume more when you remove the message queue?
    * Put a IPC_NOWAIT and control the return value of msgrcv for details of the error
    * Make some code for more help ... (although I am not a specialist in ipc)

  5. #5
    Join Date
    Jun 2009
    Posts
    105

    Re: Manipulating IPC in C language

    * The exchange of PID in the message queue are only between 2 processes only, so no one else reading these messages. What do you mean by remove the message queue? I never really had in mind the fact that deleting a message from the queue after it have been read, I thought that after being read, he removed himself from

    * With IPC_NOWAIT, it gives me my printf error and move on, but, it succeeded well to send its PID to the other!

    * This is the process code "code" and the "choice" (I put that passage in question, and other functions are not useful blabla) for which the printf is everywhere, as the multiprocess debugging with GDB is not trivial, I screwed the printf around to debug by hand!

    One last thing before looking at the heart of the matter: the ipcs are created by a separate process, that is why these 2 processes are only attached to different IPCs they need

    I have highlighted the passage in which process 1 is blocked waiting (or return -1 with IPC_NOWAIT) but I leave the variable declarations in case there would need.

    CODE.C

    Code:
    int main () 
    { 
    int PIDchoice, t sem_computer, sem_phrase, sem_letter, BAL, numeroPhrase, letterCodage; 
    char sentence [65]; 
    char conditionArret [] = "stop"; 
    char conditionArret2 [] = "STOP"; 
    struct msgbuf 
    { 
    long mtype; 
    char mtext [65]; 
    } message; 
    message.mtype = 1; 
    signal (SIGUSR1, signal_ignore) / * deviation signal * / 
    // sem_computer = semget (cle_computer, 1.0); / * semaphore count * attachment / 
    sem_phrase = semget (cle_phrase, 1.0); / * semaphore phrase attachment * / 
    sem_letter = semget (cle_letter, 1.0); / * semaphore commitment letter * / 
    t = open ( "TUBE", O_RDONLY); / * attachment to the tube called * / 
    BAL = msgget (cle_BAL, 0666); / * attachment to the mailbox * / 
    // up (sem_computer) / * increment counter * / 
    // exchange PID 
    printf ( "early exchange PID \ n"); 
    sprintf (message.mtext, "% d", getpid ()); 
    printf ( "% s is my PID \ n", message.mtext); 
    if ((msgsnd (BAL, & message, sizeof (message.mtext), 0 ))==- 1) 
    printf ( "ERROR SENDING PID"); 
    printf ( "PID sent \ n"); 
    if ((msgrcv (BAL, & message, 100.2, IPC_NOWAIT ))==- 1) 
    printf ( "ERROR RECEIVING PID \ n"); 
    printf ( "% s is the PIDchoice \ n", message.mtext); 
    PIDchoice = atoi (message.mtext); 
    printf ( "end exchange PID \ n \ n"); 
    // end exchange PID
    here is the snippet of the exchange process by PID (no prob with him, and he receives a message without sending Show me any error message):

    Want.This

    Code:
    int main () 
    { 
    int sem_computer, sem_letter, sem_phrase, BAL, PIDcode, numeroPhrase, letterCode; 
    char conditionArret [] = "stop"; 
    struct msgbuf 
    { 
    long mtype; 
    char mtext [65]; 
    } message; 
    message.mtype = 2 / * choice: message type 2 * / 
    srand (time (NULL)) / * initialize random counter * / 
    signal (SIGUSR1, signal_ignore) / * deviation signal SIGUSR1 * / 
    // sem_computer = semget (cle_computer, 0666); / * semaphore count * attachment / 
    sem_letter = semget (cle_letter, 1.0); / * semaphore commitment letter * / 
    sem_phrase = semget (cle_phrase, 1.0); / * semaphore phrase attachment * / 
    BAL = msgget (cle_BAL, 0666); / * attachment to the letter box * / 
    // semop (...& up (sem_computer)) / * increment counter * / 
    / exchange * PID * / 
    printf ( "early exchange PID \ n"); 
    msgrcv (BAL, & message, 100,1,0); 
    printf ( "% s is the PID code \ n", message.mtext); 
    PIDcode = atoi (message.mtext); 
    printf ( "PID received \ n"); 
    sprintf (message.mtext, "% d", getpid ()); 
    printf ( "% s is my PID \ n", message.mtext); 
    // if ((msgsnd (BAL, & message, sizeof (message.mtext), 0 ))==- 1) 
    // printf ( "ERROR SENDING"); 
    printf ( "FIN exchange PID \ n"); 
    / * end exchange PID * /

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Manipulating IPC in C language

    Your control of error is nothing to the extent, it does not inform you about why the error! From after the manpage of msgrcv.
    If Failed msgrcv (), errno is one of the following:

    E2BIG The message is longer than msgsz and MSG_NOERROR not t
    msgflg indicated.

    EACCES The calling process has no read permission in the
    file and not the capacitance CAP_IPC_OWNER.

    EAGAIN No message is available in the queue, and is IPC_NOWAIT
    spcifi in msgflg.

    EFAULT msgp points outside the address space.

    EIDRM The message queue was removed while t the process
    waiting for a message.

    EINTR A signal arrived before he could read anything;
    see signal (7).

    EINVAL msgqid msgsz or invalid.

    ENOMSG IPC_NOWAIT at msgflg required and no message type rclam
    exists in the queue.
    I think your mistake is in choice, you message.mtype init = 2, then you pass the message address to receive (ie the mtype is crushed! Ie mtype = 1)

    Message.mtype reset before sending the message choices!

Similar Threads

  1. Manipulating HTML document into the RealBasic
    By Borislav in forum Software Development
    Replies: 5
    Last Post: 27-07-2011, 11:10 PM
  2. Manipulating MySQL database using PHP
    By blueprats in forum Guides & Tutorials
    Replies: 1
    Last Post: 30-04-2010, 04:29 PM
  3. Manipulating Disk Images
    By Arzaan in forum Tips & Tweaks
    Replies: 3
    Last Post: 21-04-2010, 06:25 AM
  4. Manipulating a hashtable
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 01:20 AM
  5. Manipulating a Date in java
    By Linux-Us in forum Software Development
    Replies: 4
    Last Post: 07-02-2010, 02:35 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,887,929.91472 seconds with 17 queries