×
Namespaces

Variants
Actions

Pipes Example

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: spark55 (01 Oct 2007)
Last edited: hamishwillee (27 Jul 2012)
How to communicate between two threads or processes#Pipes

The following code shows the creation and usage of Pipes(the code below follows the steps given in the above link):

#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
 
int pipefd[2];
unsigned int threadid;
 
// thread entry point
void* PipeWriterThread(void* arg)
{
char ch[32];
strcpy(ch, "abcd");
write(pipefd[1], ch, 4);
return NULL;
}
 
void CreateThreadL()
{
pthread_create(&threadid,(pthread_attr_t *)NULL,PipeWriterThread, NULL);
}
 
int main()
{
if(0 == pipe(pipefd))
{
char ch[128];
CreateThreadL();
read(pipefd[0], ch, 10);
close(pipefd[1]);
close(pipefd[0]);
}
return 0;
}
This page was last modified on 27 July 2012, at 08:16.
85 page views in the last 30 days.