🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #14228

problemas con SIGIO

#14228
From: mpr100
Date: Sat, 25 Nov 2000 00:00
77 lines
2057 bytes
/*-----------------------------------------------------------------------*\
 * !No se como hacer que el proceso padre de este programa 
 * reciba una senial SIGINT cada vez que el proceso hijo le envia algo
 * por el PIPE
 * Pido ayuda. Gracias
 *
\*-----------------------------------------------------------------------*/

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>

#define BUFF_SIZE 256
#define MY_COMMAND "/home/mpr100/src/ajedrez/espera"

static int fifo[2];


static void io_available(void)
{
	char *buff[BUFF_SIZE];
	int brd;
	fprintf(stderr,"SIGIO received\n");
	brd = read(fifo[0],buff,BUFF_SIZE);
	if(brd > 0)
		write(1,buff,brd);
	return;
}


static void do_thing_1(void)
{
	printf("Doing thing 1...\n");
	sleep(rand()%5);
}
static void do_thing_2(void)
{
	printf("Doing thing 2...\n");
	sleep(rand()%5);
}

int main(void)
{
	
	pipe(fifo);
	if(!fork()) {
		/* Child code */

		close(fifo[0]);
		dup2(fifo[1],1);
		execlp(MY_COMMAND,MY_COMMAND,NULL);
	}	
	/* Father code code */
	close(fifo[1]);
	signal(SIGIO,(void *) io_available);
	dup2(fifo[0],0);
	
	fcntl(0,F_SETFL,FASYNC | O_NONBLOCK | O_ASYNC);
	fcntl(0,F_SETOWN,getpid());
	
	for(;;) {
		/* Father is busy. Will read pipe only when he receive a SIGIO */
		do_thing_1();
		do_thing_2();
		
		/* .... */
	}
	
	return 0; 
}
	
Technical Details
Message-ID: <m3r93z4rde.fsf@german2.porcelnet>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f86c8,25d7899b03e7dbdb,start
X-Google-Attributes: gidf86c8,public
From: mpr100@german2.porcelnet
Subject: problemas con SIGIO
Date: 2000/11/25
Message-ID: <m3r93z4rde.fsf@german2.porcelnet>
X-Deja-AN: 697721705
X-Complaints-To: abuse@wanadoo.es
X-Trace: m2newsread.uni2.es 975191588 62.37.145.117 (Sat, 25 Nov 2000 23:33:08 MET)
Organization: Servidor Usenet News de Uni2/Wanadoo
NNTP-Posting-Date: Sat, 25 Nov 2000 23:33:08 MET
Newsgroups: es.comp.os.linux.programacion