UNIX per-process accounting

fred p toth fpt at unccvax.UUCP
Wed Apr 16 13:40:26 AEST 1986


> I've got it (I think):
> 
> Assuming you can/will set the group of the directory to something
> indicative of which customer is involved (say, their name), you could
> create a .cshrc alias for 'cd' which will grovel out the group name
> (this could be done most easily by writing a little C program which
> just does a stat on the target, looks up the group name and prints it
> to the standard output so it can be used in a backquote arg, or you
> ...
> 	-Barry Shein, Boston University

Great idea Barry! In fact, I went down this almost exact trail for a while
before it blew up in my face. There are 2 problems:

1. shell scripts. Process number 1 charges fine, since it appears properly
	in the window between cd's. However, by the time process 2 starts,
	the user will probably have changed directories. The rest of the
	script charges to the wrong job.

2. The same problem applies to any program that spawns processes, such as
	simple programs that use system(), or popen().

I think that this problem is solvable, but only by sacrificing much of the
simplicity of your original idea. For example, there is a seldom used csh
feature that could help. If you have an alias for 'shell', when the csh
detects a shell script (non-exec-able but with x bits set), it prepends
the value of the alias to the command. So, what you get when you type
'do_stuff.sh', is maybe 'special_program do_stuff.sh'. What the special
program could do is a setregid() to establish a special group id to be
inherited by the shell script that is about to run. 

Then you have 2 types of accounting. 1) Normal processes that fall within
normal cd's. 2) Processes with special group id's that override their window
position.

Still have to do something with those programs that like to do system().

See how messy it gets?

Still, it's great to see your ideas. If you have more, bring 'em on.

Fred Toth
Washburn Graphics
Charlotte, NC
decvax!mcnc!unccvax!wgivax!fpt



More information about the Comp.unix.wizards mailing list