Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 alpha 4/15/85; site ucbvax.ARPA Path: utzoo!watmath!clyde!cbosgd!ihnp4!ucbvax!anton From: anton@ucbvax.ARPA (Jeff Anton) Newsgroups: net.unix-wizards Subject: Re: "swapfd" (more unix ideas) Message-ID: <8420@ucbvax.ARPA> Date: Sun, 23-Jun-85 19:32:22 EDT Article-I.D.: ucbvax.8420 Posted: Sun Jun 23 19:32:22 1985 Date-Received: Mon, 24-Jun-85 06:47:17 EDT References: <6954@ucbvax.ARPA> <5687@utzoo.UUCP> <288@azure.UUCP> Reply-To: anton@ucbvax.UUCP (Jeff Anton) Organization: University of California at Berkeley Lines: 47 In article <288@azure.UUCP> stevesu@azure.UUCP (Steve Summit) writes: >> 1) have a swapfd system call >> Usage: swapfd(fd1,proc,fd2) >> or possibly: swapfd(proc1,fd1,proc2,fd2) >> >> what this does, is makes procs (usually another process) fd2, to become >> my fd1, and my fd1 to become (point to a file structure) of procs fd2. > >I don't know if it's what the original submittor had in mind, but >the reason I've thought a call like this would be neat is because >you could use it to give a shell the ability to manipulate i/o >"after the fact," just like job control lets you manipulate >backgroundness/foregroundness "after the fact." Is that command >taking too long? Type control-Z and background it. Don't want >the output coming out asysynchronously? Well, I haven't thought >of a syntax, but the idea is that you want to reconnect the >standard output of the process to a file. It gets hard if the >process in question has played with its file descriptors, like >repoening file descriptor 1 as something else, or dup'ing file >descriptor 1 to some other file descriptor and then using it >there. It gets messy. It gets very messy very quickly. csh dups it's input and output descriptors to around 17 from 0,1,2. Simply assumeing 0,1,2 are stdin, stdout, and stderr is not the way to go. Also, if a process forks it's children will also need to be changed. I've worked on what I called 'deferred redirection' where you would be allowed to redirect a process group after it's started execution. I believe the most sensable solution is to allow the following call: changefds(pgrp, fd1, fd2) int pgrp, fd1, fd2; Change all occerences of file decriptors in process group pgrp that are decendants of fd1 to refer to the file fd2. Decendants of a file descriptor are dup's and a child's inherited descriptor. This can be implemented in the kernel easily by moveing the descriptors from the user structure to the process table. This call would allow a shell to change a commands input or output to a file instead of the default. However, the changes to csh were too tricky for a simple hack job. -- C knows no bounds. Jeff Anton U.C.Berkeley ucbvax!anton anton@berkeley.ARPA