#queue problem

8 messages · Page 1 of 1 (latest)

molten sinew
#

I am trying to make a small program where 2 processes send a message to their parent, he receives them, stores them and if the if condition is met within the for, it returns them but exchanging the information.

Could someone find the error? The father does not return anything, does it have to do with using IPC_PRIVATE?

I apreciate if someone can help me ❤️

midnight robinBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

molten sinew
#

the rest of the lanes if u wont to download it:

wide saffron
#

IPC_PRIVATE should be OK since all processes are forking from the same parent. Basically, using IPC_PRIVATE creates a unique key-value for every call its used in, for scenarios where you have two completely independent processes, such as a server/client relationship, you will need to create a common key, but here it should be fine.

wide saffron
#

Hmmm... A few issues I see:

I would use the message type to indicate who the message is intended for. In this simple case, it may be sufficient to just have type types (parent to child and child to parent).

Child process should send to parent with a message type indicating child to parent and should receive with a message type indicating parent to child.

Parent process should receive a message with a message type indicating child to parent from every child, not just one and send with a message type indicating parent to child.

The parent process iterates off the end of the array called "array". Use -fsanitize=address to help find where these things are happening.

=================================================================
==12728==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffffffe448 at pc 0x5555555559c9 bp 0x7fffffffe360 sp 0x7fffffffe350
READ of size 4 at 0x7fffffffe448 thread T0
    #0 0x5555555559c8 in main testMsgQueue5.c:97
    #1 0x7ffff73a9d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #2 0x7ffff73a9e3f in __libc_start_main_impl ../csu/libc-start.c:392
    #3 0x555555555324 in _start (a.out+0x1324)

Address 0x7fffffffe448 is located in stack of thread T0 at offset 168 in frame
    #0 0x5555555553f8 in main testMsgQueue5.c:27

  This frame has 4 object(s):
    [32, 40) 'aux' (line 71)
    [64, 80) 'manejador_mensaje' (line 41)
    [96, 112) 'recibido' (line 72)
    [128, 160) 'array' (line 73) <== Memory access at offset 168 overflows this variable

There may be other problems, but those are the ones I see right now.

molten sinew
#

okey

wide saffron
#

Here is a skeleton example. Pay attention to how I am using the message type.