plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

tspawnloop.c (601B)


      1 #include "u.h"
      2 #include "libc.h"
      3 #include "thread.h"
      4 
      5 void
      6 execproc(void *v)
      7 {
      8 	int i, fd[3];
      9 	char buf[100], *args[3];
     10 
     11 	i = (int)(uintptr)v;
     12 	sprint(buf, "%d", i);
     13 	fd[0] = dup(0, -1);
     14 	fd[1] = dup(1, -1);
     15 	fd[2] = dup(2, -1);
     16 	args[0] = "echo";
     17 	args[1] = buf;
     18 	args[2] = nil;
     19 	threadexec(nil, fd, args[0], args);
     20 }
     21 
     22 void
     23 threadmain(int argc, char **argv)
     24 {
     25 	int i;
     26 	Channel *c;
     27 	Waitmsg *w;
     28 
     29 	ARGBEGIN{
     30 	case 'D':
     31 		break;
     32 	}ARGEND
     33 
     34 	c = threadwaitchan();
     35 	for(i=0;; i++){
     36 		proccreate(execproc, (void*)(uintptr)i, 16384);
     37 		w = recvp(c);
     38 		if(w == nil)
     39 			sysfatal("exec/recvp failed: %r");
     40 	}
     41 }