[Coco] OS-9 "C" question

Bill Pierce ooogalapasooo at aol.com
Wed Aug 7 23:18:01 EDT 2013


Thanks Willard, that's what I was looking for.
Now, how would you reverse that to bring things back to normal for a program to keep on running normally once the forked program has closed?

Thanks again :-)

Bill Pierce
My Music from the Tandy/Radio Shack Color Computer 2 & 3
https://sites.google.com/site/dabarnstudio/
Co-Webmaster of The TRS-80 Color Computer Archive
http://www.colorcomputerarchive.com/
Co-Contributor, Co-Editor for CocoPedia
http://www.cocopedia.com/wiki/index.php/Main_Page
E-Mail: ooogalapasooo at aol.com




-----Original Message-----
From: Willard Goosey <goosey at virgo.sdc.org>
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Sent: Wed, Aug 7, 2013 10:30 pm
Subject: Re: [Coco] OS-9 "C"  question


On Wed, Aug 07, 2013 at 09:47:20AM -0400, Bill Pierce wrote:
> 
> Hi guys,
> I'm trying to make a forked program "pipe" data back to the calling program.
> All in "C" language in OS-9 Level 2

The trick that makes this all work is that dup() always returns the
*lowest* possible path number...

Here's an old OS-9 C program of mine that does that....
-----------<lookterm2.c>-----------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <modes.h>
#define MARK "/dd/tmp/term_win"

main(argc,argv)
    char *argv[];
{
  int pipe,sin,sout,status,marker;
  char line[80];
  if((pipe=open("/pipe",3))>0)
  {
     sin=dup(0);  /*save a copy of standard in*/
     sout=dup(1); /*save a copy of standard out*/
     close(0);    /*close stdin*/
     dup(pipe);   /*path 0 is now pipe*/
     close(1);    /*close stdout*/
     dup(pipe);   /*path 1 is now pipe*/
	/*forked process inherits paths 0,1,2*/
     os9fork("ident",8,"-m term\n",1,1,0);
     close(0);	  /*parent: close pipe 0 */
     dup(sin);	  /*path 0 is now saved stdin*/
     close(1);    /*close pipe output*/
     dup(sout);   /*path 1 is now saved stdout*/

     while(readln(pipe,line,80)>0)
     {
#ifdef DEBUG
       if(argc>1)
           writeln(1,line,80);
#endif
       if(strncmp(line,"Module CRC:",11)==0)
         {
          if(strncmp(&(line[13]),argv[1],7)==0)
            {
               marker=creat(MARK,S_IWRITE);  /*unlike the raw asm */
               close(marker);                /*sys call, C creat dont */
            }                                /*bomb out if file exists */
          else
            {
               if(access(MARK,S_IREAD)==0) /*file does exist*/
                 {
                    unlink(MARK); /*delete it*/
                 }
            }
         }
          
     }
     wait(&status); /*wait for child to exit */
  }
  else
  {
    writeln(2,"Couldn't open pipe",80);
    exit(216);
  }
}
------------------<lookterm2.c>--------------------------------
BTW what this does, is take as an arguement a module CRC, asks "ident"
for the CRC of the /term descriptor, and creates an empty file in
/dd/tmp if it matches.  This let me use the same startup for both 
windint only and vdgint only boot disks...


Willard
-- 
Willard Goosey  goosey at sdc.org
Socorro, New Mexico, USA
I search my heart and find Cimmeria, land of Darkness and the Night.
  -- R.E. Howard

--
Coco mailing list
Coco at maltedmedia.com
http://five.pairlist.net/mailman/listinfo/coco

 



More information about the Coco mailing list