Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!lll-lcc!ames!hc!hi!josh From: josh@hi.UUCP Newsgroups: comp.unix.questions Subject: Re: A couple questions Message-ID: <4173@hi.uucp> Date: Tue, 14-Apr-87 13:57:39 EST Article-I.D.: hi.4173 Posted: Tue Apr 14 13:57:39 1987 Date-Received: Wed, 15-Apr-87 05:47:02 EST References: <3164@jade.BERKELEY.EDU> Reply-To: josh@hi.UUCP (Josh Siegel) Organization: U. of New Mexico, Albuquerque Lines: 74 In article <3164@jade.BERKELEY.EDU> marcp@beryl.berkeley.edu (Marc M. Pack) writes: >Hello! I've a couple of questions in UNIX 4.2. > >1. How do programs like "more" distinguish between text files and > executable files? Hopefully, there's something surer than > just taking a sample of a file and testing it. I think this is the way it does it. First it stat's it to see if it is a directory then it reads in some of it to see if it is ascii. > >2. Is it possible to, while in a C program, call another program and > put it into the background? Actually, I know it's possible, > 'cause I can do it with a line like: > > system("cat textfile &"); > > This won't work, however, if I try to "more" the file instead. > What determines what can be put in the background and what can't? > Is there some way to run a program from within a program, and have > it return upon completion to the original program besides "system"? > (The execl series, of course, doesn't return.) This is a loaded question and can become far more complicated then you know... The command more(1) checks to see if it is run on a terminal (a tty). This is why "more" will not run in a system() call. You CAN put almost anything in the background, it is just harder if it requires to be run on a terminal (talk(1), more(1), etc). A short source for system might look like (Hmm...): system(string) char string[]; { if(vfork()) { return(wait(0)); } else { ... parse string ... execl(prog,args); } } /* This is not a complete system() but I am writting it from memory. */ If you wish to run a more(1) or a talk(1) or rogue(6), it requires the program to open a pty. This makes the program (more) think it is on a terminal while it really is not. This is how rlogin works. Try the following: 1) Set up a .rhosts file in your home directory 2) rsh to that account using the following command: % rsh {machine} /bin/csh -i 3) Try doing a "more" of a file. Gets sick eh? This is one reason why pty's were invented. I have a whole library of routines for networking, ptys, etc that I can post if there are any requests for it... > >Thanks for your time, > > Marc M. Pack Hope I was helpful --Josh Siegel -- Josh Siegel (siegel@hc.dspo.gov) (505) 277-2497 (Home) I'm a mathematician, not a programmer!