please dont rip this site

language ccpp CREF EXAMPLES pipe2

/ ****************************************************************
 *
 * Purpose: Basic example of pipe. 
 *          Read and write variable length records across a pipe.
 *
 * Author:  M J Leslie
 *
 * Date:    17 Apr 96
 *
 ****************************************************************/

#include <sys/types.h>
#include <unistd.h>			/* pipe.			*/
#include <signal.h>

void Child  (pid_t Handle);
void Parent (pid_t Handle);

main()
{

  pid_t		Pid;
  int 		fd[2];

  pipe(fd);				/* Create two file descriptors  */

  Pid = fork();

  if ( Pid == 0)			/* Child                        */
  {
    close(fd[0]);
    Child(fd[1]);
    puts("Child end");
  }
  else					/* Parent			*/
  {
    close(fd[1]);
    Parent(fd[0]);
    puts("Parent end");
  }
}

/****************************************************************
 *
 *	The Child sends data to the parent.
 *
 ****************************************************************/

void Child(pid_t Handle)
{
  int Len;

  char Buff[50]="Bass Beer";

  Len = strlen(Buff)+1;
  write(Handle, &Len, sizeof(Len));
  write(Handle, Buff, Len);

  strcpy(Buff, "Wild times.");
  Len = strlen(Buff)+1;
  write(Handle, &Len, sizeof(Len));
  write(Handle, Buff, Len);

  strcpy(Buff, "Alex was ere.");
  Len = strlen(Buff)+1;
  write(Handle, &Len, sizeof(Len));
  write(Handle, Buff, Len);

  strcpy(Buff, "Bon Jovi rules the world.");
  Len = strlen(Buff)+1;
  write(Handle, &Len, sizeof(Len));
  write(Handle, Buff, Len);  
  
  close(Handle);
}

/****************************************************************
 *
 *	Read the data sent by the child.
 *
 ****************************************************************/

void Parent(pid_t Handle)
{

  int		Len;
  char 		Buff[50];

  /* ...	Perform two reads. THe first gets the length of the data
     ...	the second gets the actual data.			*/

  while (read(Handle, &Len, sizeof(Len)) > 0)
  {
    read(Handle,Buff, Len);
    printf("%s\n", Buff);
  }
      
}







file: /Techref/language/ccpp/CREF/EXAMPLES/pipe2.c, 1KB, , updated: 1997/4/21 09:52, local time: 2012/5/25 07:25,
TOP NEW HELP FIND: 
38.107.179.233:LOG IN

 ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/techref/language/ccpp/CREF/EXAMPLES/pipe2.c"> language ccpp CREF EXAMPLES pipe2</A>

Did you find what you needed?

 
Stepper motors CAN be smooth!
And stepper controllers can be strong and cheap. Roman Black's Linistep stepper controller kits:
o 18th microstep
o Linear smoothing
  o Open source
o Full kit $25!
 

SX MASTERS: Eric Smith and Richard Ottosen's SERVID is an intellegent RS232 video terminal (4x20 character display) in one chip. See the write up here..

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .