Results 1 to 10 of 12
Hi everyone, how do you implement a pipe between 2 distinct process that shares data to process it, in a producer-consumer like system???
I must thank any incoming hekp....
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-15-2007 #1
Help on PIPES
Hi everyone, how do you implement a pipe between 2 distinct process that shares data to process it, in a producer-consumer like system???
I must thank any incoming hekp.
- 03-15-2007 #2
I really don't understand your question.
Are you referring to having a process communicate with a completely separate process that was not started by the current process? If so, you should look into FIFOs (aka 'named pipes').
If not, please clarify your question.
- 03-16-2007 #3
Re:Pipes
That's right.
I'm trying to implement one of those. A process independent from another, ona process must connect with the other sending data trough the piper mechanism,but i don't understand how to implement it.
Can you help me??
- 03-16-2007 #4Linux User
- Join Date
- Aug 2005
- Posts
- 408
Sounds like a homework problem?
A pipe looks like this: |
It's the key below the backspace key on many keyboards.
You use it to connect different processes, just like you keep saying, by putting it between two processes.
For example:
The output of the ps command here gets piped to the input of the grep command. There are lots of places where you can read about this.Code:ps ax | grep firefox
- 03-16-2007 #5
This does sound like a homework question, but I will explain pipes.
If you want one program to nicely move into another, you can connect them with a pipe (|). This connects the stdout of the first to the stdin of the second. So for instance:
This runs 'locate my_file', and instead of printing the output to the terminal, sends it instead to grep. grep then searches locate's output for '/home'.Code:locate my_file | grep '/home'
Does this make sense?
Alternatively, there is a concept called named pipes, that essentially are files, except that they don't actually store anything on the disk: they are simply a way for processes to communicate. If this is what you need, tell me, and I can explain them some more.
Does this make sense? Is there any particular problem you have with piping?
- 03-17-2007 #6
Pipes with process
Ok, i need to make 2 programms, the programms really don't matter, i know some of C language, the problem comes with the implementation of pipes between them.
I need to send data from one to another in real time, like you said, 2 distinct process sharing data and no HD writting. Really it's a homework problem, so basic, and i must thank for the help.
- 03-17-2007 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
OK, now it's clear, you want to do it with C.
It isn't necessary to realize this with 2 separate programs. Check your manuals for the pipe() and the fork() function.
Regards
- 03-20-2007 #8
Error in gcc
Now, i've read about pipe() and fork() function. The problem now comes with the GNU C Compiler (gcc). The code (i'm no sure it's ok), is:
///////////////////////// C Code so use pipe
#define MAXLINEA 100
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main (void)
{
int pipes[2];
if (!pipe(pipes))
{
close(pipes[0]);
int num;
num=random(10)+1;
printf("numero generado: %d",num);
//int fd;
//char Buff[]="V8 cars are coool";
write(pipes[1],num,4);
close(pipes[1]);
}
}
Whe i try to compile it, i receive errors with the include files, it reads:
----------------------------------------------------------------------------------------------
zack@zack-laptop:~/Desktop/manuales$ gcc pipas.c
En el fichero incluído de pipas.c:2:
/usr/include/stdlib.h:33:20: error: stddef.h: No existe el fichero ó directorio
In file included from pipas.c:2:
/usr/include/stdlib.h:140: error: syntax error before ‘__ctype_get_mb_cur_max’
In file included from /usr/include/sys/types.h:266,
from /usr/include/stdlib.h:433,
from pipas.c:2:
/usr/include/bits/pthreadtypes.h:50: error: syntax error before ‘size_t’
/usr/include/bits/pthreadtypes.h:53: error: syntax error before ‘__stacksize’
In file included from pipas.c:2:
/usr/include/stdlib.h:450: error: syntax error before ‘size_t’
/usr/include/stdlib.h:480: error: syntax error before ‘size_t’
/usr/include/stdlib.h:584: error: syntax error before ‘__size’
/usr/include/stdlib.h:586: error: syntax error before ‘__nmemb’
/usr/include/stdlib.h:595: error: syntax error before ‘size_t’
In file included from /usr/include/stdlib.h:606,
from pipas.c:2:
/usr/include/alloca.h:33: error: syntax error before ‘__size’
In file included from pipas.c:2:
/usr/include/stdlib.h:611: error: syntax error before ‘__size’
/usr/include/stdlib.h:768: error: syntax error before ‘size_t’
/usr/include/stdlib.h:773: error: syntax error before ‘size_t’
/usr/include/stdlib.h:846: error: syntax error before ‘size_t’
/usr/include/stdlib.h:849: error: syntax error before ‘size_t’
/usr/include/stdlib.h:853: error: syntax error before ‘size_t’
/usr/include/stdlib.h:857: error: syntax error before ‘size_t’
/usr/include/stdlib.h:866: error: syntax error before ‘size_t’
/usr/include/stdlib.h:869: error: syntax error before ‘*’ token
/usr/include/stdlib.h:873: error: syntax error before ‘wchar_t’
/usr/include/stdlib.h:877: error: syntax error before ‘mbstowcs’
/usr/include/stdlib.h:877: error: syntax error before ‘*’ token
/usr/include/stdlib.h:880: error: syntax error before ‘wcstombs’
/usr/include/stdlib.h:881: error: syntax error before ‘*’ token
In file included from /usr/include/_G_config.h:44,
from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from pipas.c:3:
/usr/include/gconv.h:72: error: syntax error before ‘size_t’
/usr/include/gconv.h:88: error: syntax error before ‘size_t’
/usr/include/gconv.h:97: error: syntax error before ‘size_t’
/usr/include/gconv.h:174: error: syntax error before ‘size_t’
/usr/include/gconv.h:177: error: syntax error before ‘}’ token
In file included from /usr/include/libio.h:32,
from /usr/include/stdio.h:72,
from pipas.c:3:
/usr/include/_G_config.h:47: error: el campo ‘__cd’ tiene tipo de dato incompleto
/usr/include/_G_config.h:50: error: el campo ‘__cd’ tiene tipo de dato incompleto
In file included from /usr/include/stdio.h:72,
from pipas.c:3:
/usr/include/libio.h:354: error: syntax error before ‘size_t’
/usr/include/libio.h:363: error: syntax error before ‘size_t’
/usr/include/libio.h:479: error: syntax error before ‘_IO_sgetn’
/usr/include/libio.h:479: error: syntax error before ‘size_t’
In file included from pipas.c:3:
/usr/include/stdio.h:302: error: syntax error before ‘size_t’
/usr/include/stdio.h:309: error: syntax error before ‘size_t’
/usr/include/stdio.h:351: error: syntax error before ‘size_t’
/usr/include/stdio.h:355: error: syntax error before ‘size_t’
/usr/include/stdio.h:603: error: syntax error before ‘fread’
/usr/include/stdio.h:603: error: syntax error before ‘size_t’
/usr/include/stdio.h:609: error: syntax error before ‘fwrite’
/usr/include/stdio.h:609: error: syntax error before ‘size_t’
/usr/include/stdio.h:631: error: syntax error before ‘fread_unlocked’
/usr/include/stdio.h:631: error: syntax error before ‘size_t’
/usr/include/stdio.h:633: error: syntax error before ‘fwrite_unlocked’
/usr/include/stdio.h:633: error: syntax error before ‘size_t’
pipas.c: En la función ‘main’:
pipas.c:12: error: demasiados argumentos para la función ‘random’
-----------------------------------------------------
I understand, obviously that says there is no such includes on INCULDE directory. I trie downloading it from: http://www.koders.com/c where i found that includes, after that i copied it on my system INCLUDE directoy: /usr/lib/gcc/i486-linux-gnu/4.0.3/include, when i compile the source code, to short, it marks a lot of errors. I'm using Ubuntu 6.06. I install gcc with:
sudo apt-get install build-essential
it installs g++, but i receive the same errors, something with the include files i download.
Is there another way to install gcc or g++ that configures the INCLUDES by itself and not make problems??
- 03-20-2007 #9
I find it interesting that gcc switches between languages
.
Anyway, the include directory for gcc is /usr/include. Note that 'gcc' is a C compiler, while 'g++' is a C++ compiler. Make sure that you have the proper headers in /usr/include.
If they are there, and this still isn't working: do any C files work for you?
- 03-20-2007 #10Just Joined!
- Join Date
- Mar 2007
- Location
- Hyderabad, India
- Posts
- 2
Instead of pipes use message queues.
Message queues are easy to use than pipes i think. u can search in google about message queues and in GCC manual u can find the required explanations with examples


Reply With Quote
