ss@wanginst.UUCP (Sid Shapiro) (02/13/85)
Hi there unix-folks. In keeping with the discussions of a few weeks ago about how to automatically kill backgrounded process from the csh upon logout, I thought I'd ask the question another way. Or at least I thought I'd take another shot at it. I thought, if I could simply record the pid of the process in a file or variable, then, golly, killing it later would be easy. So I cheerfully set off to try and figure out how to capture the pid that is returned when you type foo& Well, after I exhausted all the variations I could think of, I went to the csh sources. It sure looked to me like the shell simply does a printf of the pid. But I'll be darned if I can redirect or backquote or set something to get that number. Can anyone offer words of wisdom? Thanks, Sid Shapiro -- Wang Institute of Graduate Studies [apollo, bbncca, ucadmus, decvax, linus, masscomp]!wanginst!ss ss%wang-inst@Csnet-Relay.ARPA (617)649-9731
msb@lsuc.UUCP (Mark Brader) (02/14/85)
ss@wanginst.UUCP (Sid Shapiro) writes: > So I cheerfully set off to try and figure out how to capture the pid > that is returned when you type foo& > > Well, after I exhausted all the variations I could think of, I went to > the csh sources. It sure looked to me like the shell simply does a > printf of the pid. But I'll be darned if I can redirect... In sh, on the other hand, you need only type: (foo&) 2>foo.pid Mark Brader
rpw3@redwood.UUCP (Rob Warnock) (02/14/85)
+--------------- | ss@wanginst.UUCP (Sid Shapiro) writes: | > So I cheerfully set off to try and figure out how to capture the pid | > that is returned when you type foo& | In sh, on the other hand, you need only type: (foo&) 2>foo.pid | Mark Brader +--------------- In the Bourne Shell (either Edition 7 or 4.1bsd) the (parent) shell variable "$!" contains the process number of the last background process evoked. You don't need to write it into a file. Try: $ foo & $ ... # anything but another background invocation $ echo $! It works as documented. See "sh(1)". Rob Warnock Systems Architecture Consultant UUCP: {ihnp4,ucbvax!dual}!fortune!redwood!rpw3 DDD: (415)572-2607 USPS: 510 Trinidad Lane, Foster City, CA 94404