	subroutine getuser(terminal,username)
	IMPLICIT NONE
	character*(*) terminal
	character*(*) username
c  find username from terminal name

	INCLUDE '($DVIDEF)'
	INCLUDE '($JPIDEF)'
	INCLUDE '($SSDEF)'
	INTEGER LIB$GETDVI,LIB$GETJPI,PID, istat

c  should even go across the network ???

d	write(6,*) terminal,username
	username = ' '
	istat = lib$getdvi(%ref(dvi$_pid),,terminal,pid,,)
	if(.not.istat) then
		if(istat.eq.ss$_ivdevnam.OR.istat.eq.ss$_nosuchdev) return
		call exit(istat)
	endif
d	print '(1x,z8.8)',pid
	if(pid.ne.0) then
	   istat = lib$getjpi(%ref(jpi$_username),pid,,,username,)
	   if(.not.istat) call exit(istat)
	endif	   
d	write(6,*) terminal,username

	return
	end
