×
Namespaces

Variants
Actions
Revision as of 07:33, 9 December 2011 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 07:33.
90 page views in the last 30 days.
×