-- Laurent DENIEL | E-mail: deniel_at_worldnet.fr Paris, FRANCE | deniel_at_fr.airsysatm.thomson-csf.com | WWW : http://www.worldnet.fr/~deniel All above opinions are personal, unless stated otherwise. Would this do it for you? # Interactive process -- returns "tty..." or possibly "console" $ ps -o tty -p $$ | tail -1 ttyp0 # Known non-interactive process -- returns "??" $ ps -o tty -p 1 | tail -1 ?? -Bob Jones I have see something for a graphic software. The solution the developpers use is to give two names to the executable file (by means of a link). So when the software is launched, arg[0] is different according to the name which was used. ___________________________________________________________________ Marie-Claude Vialatte | Telephone : +33 4 73 40 77 08 CUST | Fax : +33 4 73 40 75 10 BP 206 | Email : mc.vialatte_at_cust.univ-bpclermont.fr 63174 AUBIERE Cedex | WWW : http://cust.univ-bpclermont.fr Steve, With the test if [ -t 2 -a -t 1 ] you can check if the open file with file descriptor number 2 or 1 is associated with a terminal device. This tells you if a process is excuted from a interactive login or from a batch program. An other check you can do is to compare the output from the commands 'whoami' and 'who am i'. If there is a difference, the real and effective userid is different, meaning that the .profile is excuted by doing 'su - <user>'. Regards, Rob Pieters Do a "w" or "who" look for the controlling tty, such as, ttyp1. enterprise 229> w 10:08am up 177 days, 23:27, 3 users, load average: 0.00, 0.00, 0.00 User tty login_at_ idle JCPU PCPU what snabouls ttyp1 26Apr98 20:09 2 -csh snabouls ttyp2 15Feb9877days 2:09 2 -sh klarsen ttyp4 14Apr98 37 96:01 8:05 /usr/openwin/bin/mailtool -Wp 0 enterprise 230> who snabouls ttyp1 Apr 26 19:52 (yorick) snabouls ttyp2 Feb 15 21:13 (129.92.2.58:0.0) klarsen ttyp4 Apr 14 12:46 (watchdog) Kristin L. Larsen aka) "Hey you!" System Administrator, AFIT/ENY Wright-Patterson Air Force Base, Ohio ICES contractor klarsen_at_afit.af.mil AFIT e-mail I doubt if what below is useful to you, It's something I use in csh scripts. I have scripts which need to know whether they are interactive or not. In such case I use a construct like : source $a/ifinteractive if ($flag != "interactive") goto purge The "ifinteractive" procedure is found below (I used it on SunOS, Ultrix and Alpha, therefore it contains redundant stuff, but the idea is to look at the output of "ps"). Maybe you can figure out something. ------------------------------------------------------------------------ ---- Lucio Chiappetti - IFCTR/CNR - via Bassini 15 - I-20133 Milano (Italy) ------------------------------------------------------------------------ ---- Fuscim donca de Miragn E tornem a sta scio' in Bregn Che i fachign e i cortesagn Magl' insema no stagn begn Drizza la', compa' Tapogn (Rabisch, II 41, 96-99) ------------------------------------------------------------------------ ---- For more info : http://www.ifctr.mi.cnr.it/~lucio/personal.html ------------------------------------------------------------------------ ---- # # L.Chiappetti - IFCTR - Aug 90 # # Version 1.0 - Aug 90 - Original version # Version 1.1 - Apr 91 - installed in /usr/local # Version 1.1 - Jun 91 - manually recovered after disk crash # Version 1.2 - Nov 92 - changes in Sun ps + ps for DECstation # Version 1.3 - Sep 96 - added support for Alpha # # The REAL PROGRAMMER TOOLS package # # this little piece of code, when SOURCED within a script # will return a value in flag of "interactive" or "not" # # interactive is defined a script which : # a) is SOURCED from csh (current process is -csh) # b) is called as a script from csh (parent process is -csh) # c) is SOURCED within a case b script # while it is not interactive if # d) is called from another script (parent process is not -csh) # # please note the parentheses in the if have to be left alone !!! # # unfortunately there is no way to tell whether the script # is running in background or foreground # a background script under conditions a-c will appear as interactive # # variable DECSTATION is set in .cshrc at IFCTR, what follows is # for other sites # #if (! $?DECSTATION) then set DECSTATION = 0 set ALPHA = 0 if (-f /bin/machine) then if (`/bin/machine` == 'mips') then set DECSTATION = 1 endif # if not a DECstation it might be an Alpha if (`/bin/machine` == 'alpha') then set DECSTATION = 1 set ALPHA = 1 endif endif #endif # # this is good on Sun # if ($DECSTATION) goto dec set temp = `ps -l$$ | grep $$` # if ($temp[14] == "-bin/csh" && $temp[15] == "(csh") then # Sun changed ps if ($temp[14] == "-csh" && "$temp[15]" == "(csh)" ) then set flag = "interactive" else set ppid = $temp[4] set temp = `ps -l$ppid | grep $ppid` # if ($temp[14] == "-bin/csh" && $temp[15] == "(csh") then # Sun changed ps if ($temp[14] == "-csh" && "$temp[15]" == "(csh)") then set flag = "interactive" else set flag = "not" endif endif goto end dec: # # this is good on DEC (the syntax of ps output is different) # if ($ALPHA) goto alpha set temp = `ps -l$$ | grep $$` if ("$temp[15]" == "-" && "$temp[16]" == "(csh)" ) then set flag = "interactive" else set ppid = $temp[4] set temp = `ps -l$ppid | grep $ppid` if ("$temp[15]" == "-" && "$temp[16]" == "(csh)" ) then set flag = "interactive" else set flag = "not" endif endif alpha: # # this is good on ALPHA (the syntax of ps is TOTALLY different) # # DO NOT use the BSD compatbile syntax, but build a new output string # set temp = `ps l$$ | grep $$` set temp = `ps -p $$ -o pid,ppid,command | grep $$` echo $temp # if ("$temp[14]" == "-u" && "$temp[15]" == "(csh)" ) then if ("$temp[3]" == "-u" && "$temp[4]" == "(csh)" ) then set flag = "interactive" else set ppid = $temp[2] set temp = `ps -p $ppid -o pid,ppid,command | grep $ppid` echo $temp if ( ("$temp[3]" == "-u" || "$temp[3]" == "-sh" ) && "$temp[4]" == "(csh)" ) then set flag = "interactive" else set flag = "not" endif endif endif end:
This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:37 NZDT