On Thu, Jul 14, 2011 at 06:30:21AM -0500, Martin McCormick scribbled:
> #After the step, we should have two file descriptors.
> (gdb) output leftchannel_pipe
> {7, 8}
[...]
> #that also looks right, but let's try to write to leftchannel_pipe.
> main () at 2pipes.c:98
> 98      fwrite(&leftbyte,sizeof(leftbyte),1,leftchannel_pipe[1]);
> (gdb) step
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0xb76a78d1 in fwrite () from /lib/i686/cmov/libc.so.6
> 
>       That looks like what you get when confusing the contents
> of a pointer with the name of that pointer but the fwrite
> statement is what I used when writing to a normal file and that
> worked.

It also happens when you try to use 7 as a pointer.

Note that fwrite does not take a file descriptor but a FILE*. I'm
not sure what options you're passing gcc, but I would have
expected it to at least warn you that you were passing an int as
a pointer.

Rather than using fwrite() you could just use write(), which takes a
file descriptor. Alternately, if you really want to use fwrite or
other stdio functions rather than the *nix syscalls, you could
use fdopen() to get a FILE* corresponding to the pipe's fd.

If you check the pipe manpage, you'll find an example of how to
use pipes.

Also, I'm not sure what kind of modules you're writing, but if
they both live in the same address space, then using pipes is
like calling your cellphone from your work phone so that you can
talk to yourself. If your modules are separate processes, then
that's exactly what pipes are for.

Ivan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110714162537.ga26...@mrph.org

Reply via email to