9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] trying to understand how fork/pipe a filtering program
@ 2006-08-30 22:46 Axel Belinfante
  2006-08-30 23:05 ` geoff
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Axel Belinfante @ 2006-08-30 22:46 UTC (permalink / raw)
  To: 9fans

after the suggestion of resample(1) some days ago
I've tried run it as a filter from another program.
this other program is non-threaded; for testing all
it does is call initdraw and read an image file
after which the resample routine is called.

in my resample routine it seems I need a call to sleep
to avoid the resample program to hang (in Pread).
(replacing the sleep by a fprint(2, "something\n") works too).

I'm just trying to understand what goes on -
is this the way to do this? if not, what am I missing?
I'm sorry if it is something obvious; I'm just trying to learn.

Axel.

Image*
resample(Image *from)
{
	int p[2];
	Image *img;

	if(pipe(p) < 0){
		fprint(2, "pipe fails: %r\n");
		exits("Epipe");
	}
	switch(fork()){
	case -1:
		fprint(2, "fork fails: %r\n");
		exits("Efork");
	default:
		if (writeimage(p[0], from, 0) < 0)
			fprint(2, "error writeimage\n");
		close(p[0]);
		/* seems we need sleep to give up cpu so resample can run */
		sleep(1);
		img = readimage(display, p[1], 0);
		close(p[1]);
		waitpid();
		return img;
	case 0:
		dup(p[1], 0);
		dup(p[0], 1);
		execl("/bin/resample", "resample", "-x50%", nil);
		fprint(2, "execl fails: %r\n");
		exits("Eexec");
	}
	return nil;
}



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2006-09-04 20:50 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-30 22:46 [9fans] trying to understand how fork/pipe a filtering program Axel Belinfante
2006-08-30 23:05 ` geoff
2006-08-31 16:26 ` "Nils O. Selåsdal"
2006-08-31 19:55   ` Axel Belinfante
2006-08-31 20:15     ` rog
2006-08-31 20:24       ` Axel Belinfante
2006-08-31 20:24     ` rog
2006-08-31 20:45       ` Axel Belinfante
2006-09-01  3:43     ` geoff
2006-09-01 10:57       ` rog
2006-09-01 14:35 ` rog
2006-09-01 15:33   ` Skip Tavakkolian
2006-09-01 15:59     ` rog
2006-09-01 18:42       ` Skip Tavakkolian
2006-09-03 19:09   ` Axel Belinfante
2006-09-04 14:52     ` Gorka guardiola
2006-09-04 20:50       ` Gorka guardiola
2006-09-04 19:26     ` Skip Tavakkolian
2006-09-04 20:25       ` Francisco J Ballesteros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).