×
Namespaces

Variants
Actions

Exemplos de pipes

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

Artigo
Tradução:
Originado de Pipes Example
Por kyllercg
Última alteração feita por hamishwillee em 09 Dec 2011



Pipes (dutos)

O código a seguir mostra como criar e usar pipes.

#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
 
int pipefd[2];
unsigned int threadid;
 
// Início da thread
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 9 December 2011, at 04:33.
67 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×