[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

641.0. "Check for subprocesses on LOGOUT?" by LEROUF::STADTELMEYER (L'enfer, c'est les autres) Thu Dec 24 1987 07:11

	Hello there,

	I spawn my editing sessions to be able to quickly attach back to
        my main process without having to leave the editor. Now if I happen
        to have an editor subprocess sleeping when I log out of my main 
        process, the subprocess is also stopped without warning and my edits
        are lost (unless I explicitely recover them).

        What do I have to include in my LOGOUT.COM to check if certain 
        subprocesses exist? I checked the F$GETJPI and F$PID, but they don't
        seem to do what I want. A DCL command $ SHOW PROCESS/SUBPROCESS
        is not smart enough.
        
        Any ideas?
        
        	Axel
T.RTitleUserPersonal
Name
DateLines
641.1Try this outUFP::MURPHYRick - WA1SPT/4Thu Dec 24 1987 11:3936
    Try this - it's not tested, but it's simple enough.
    You could change the "$ my_pid = f$getjpi("","PID")" to
    	$ my_pid = f$getjpi("","MASTER_PID") and the
    	$ if f$getjpi(proc_pid,"OWNER") .NES. my_pid then goto look_for_process
    	to f$getjpi(proc_pid,"MASTER_PID") which should find ANY processes
    	in your job, if that's what you want..
    	-Rick
    
    $ subprocess_count = 0
    $ !
    $ ! Turn off GROUP and WORLD privs so that you only see processes
    $ ! with your UIC.
    $ !
    $ my_pid = f$getjpi("","PID")
    $ old_privs = f$setprv("NOGROUP,NOWORLD")
    $ look_for_process:
    $ proc_pid = f$pid(context)
    $ if proc_pid .eqs. "" then goto check_count
    $ !
    $ ! Found a process with my UIC - is the current process it's parent?
    $ !
    $ if f$getjpi(proc_pid,"OWNER") .NES. my_pid then goto look_for_process
    $ if subprocess_count .gt. 0 then goto give_name
    $ write sys$Output "You have the following subprocess(es):"
    $ give_name:
    $ subprocess_count = subprocess_count + 1
    $ write sys$output f$fao("!_!15AS running !AS",-
    		f$getjpi(proc_pid,"PROCNAME"),f$getjpi(proc_pid,"IMAGNAME"))
    $ goto look_for_process
    $ check_count:
    $ if subprocess_count .eq. 0 then goto exit
    $ read/prompt="Do you still want to logout? " sys$command answer
    $ if answer then logoutt
    $ exit:
    $ privs = f$setprv(old_privs)
    $ exit
641.2Or...NRADM5::COTEWho cares about footballMon Dec 28 1987 11:473
$ IF F$GETJPI("","JOBPRCCNT") .EQ. 1 THEN LOGOUT
$ WRITE SYS$OUTPUT "Other processes in job still active!"
$ EXIT
641.3Try the LOGOUT tool in the ToolshedDSSDEV::MUNYANSteve MunyanWed Dec 30 1987 02:3310
    
    Or you might try the LOGOUT tool in the toolshed.  In addition to
    telling you that there are sub-processes around, it displays the
    subprocesses that will be deleted if you continue logging out in
    a manner similar to SHOW PROC/SUB.  It then asks you if you want
    to continue logging out.
    
    Steve
    LOGOUT developer/maintainer
    
641.4Procedure to count Interactive processesCSSAUS::BENHAMLewis Benham : Sydney , Australia !Mon Jan 04 1988 04:4836
$ !
$ !   	I have a simple command file which checks only for interactive
$ !processes and sets a variable which may then be read by any subsequent command.
$ !It works as follows. Firstly the number of processes in the job are counted
$ !in the process_loop section. Then using this number the processes inthe
$ !job are each checked if they are interactive. The varible num_int_pro then
$ !contains the number of interactive processes in the job... Easy!
$ !
$ !
$ ! Command file to count the number of current interactive processes
$ ! and set the variable num_int_pro
$
$ num_pro = 0
$ num_int_pro = 0
$
$ process_loop :
$	if f$pid( dummy_1 ) .eqs. "" then goto got_num_pro
$	num_pro = num_pro + 1
$	goto process_loop
$
$ got_num_pro :
$	if f$getjpi( f$pid( dummy_2 ) , "MODE" ) .nes. "INTERACTIVE" -
		then goto not_interactive
$	num_int_pro = num_int_pro + 1
$
$ not_interactive :
$	num_pro = num_pro - 1
$	if num_pro .gt. 0 then goto got_num_pro
$	
$
$ got_num_int_pro :
$	num_int_pro :== 'num_int_pro'
$
$ exit
$

641.5I use thisTKOV60::S_IKEDAShinichiro Ikeda, SWS/JapanThu Jan 07 1988 01:5191
    RE: .2       

    Using f$getjpi("","jobprccnt") is no good.  Sometimes we use spawn
    command without any qualifiers and parameters. When we want to logged
    out from subprocess, we cannot with warning message.

        $ spawn
        %DCL-S-SPAWNED, process S_IKEDA_1 spawned
        %DCL-S-ATTACHED, terminal now attached to process S_IKEDA_1
        $
        ....
        $ logout
        Other processes in job still active!
        $


    I will show you my logout.com, and he works as follows:

        o Check your subprocess. If you have any subprocess, this one
          warn you and shows these processes.

        o Check the remote login or not.  Someone use SET HOST command
          and logged in your account, this one sends mail to remote
          user and yourself.


    Thanks,

    - Shin


-------- Cut here --------
$								v = 'f$verify(0)
$!
$!  Procedure:  logout.com
$!
$!  Author:     Shinichiro Ikeda    16-Jul-1987
$!
$!  Usage:      Put this line in your login.com.
$!
$!                $ lo*gout :== @logout
$!
$!  Description:
$!
$!    This procedure allows you to check your subprocess before
$!    logged out.  If you have any subprocess, this one warn you
$!    and shows these processes.
$!    And, before actually logout, check your process is remote
$!    login, if so send mail(that identifying who is using your
$!    account) to remote user and yourself.
$!
$!
$ if f$mode() .nes. "INTERACTIVE" then goto end_of_procedure
$
$    if f$getjpi("","PRCCNT") .eqs. "0" then goto logout_true
$    bell[0,8] = 7
$    write sys$output bell + "%DCL-E-SUBEXIST, sub-process exist"
$    show proc/sub
$    goto end_of_procedure


$logout_true:
$
$    on warning then goto final
$    if f$getjpi("","OWNER") .nes. "" then goto final  ! I'm subprocess
$    recall/save sys$login:rb$logout.dat               ! Save recall-buffer
$
$! Check remote login
$    term = f$trnlnm("tt")
$    termtype = f$extruct(0,2,term)
$    if termtype .nes. "RT" then goto final
$
$    username = "''f$edit(f$getjpi("","username"),"trim")'"
$    address = f$trnlnm("sys$node") + username
$    rem_id = f$trnlnm("sys$rem_id")
$    rem_node = f$trnlnm("sys$rem_node")
$    rem_address = rem_node + rem_id
$    time = f$time()
$
$    if rem_address .eqs. address then goto final
$
$    mail/self/subject="Set host by ''rem_address'  at ''time'" -
         nl: 'rem_address'
$
$final:
$    logoff
$    exit


$end_of_procedure:
$    if v then set verify
641.6Yet Another WayRAINBO::LONGWhat does it mean - exact change?Mon Jan 11 1988 19:055
    I have a C program which does exactly what .0 wants.  If anyone
    would be interested in a copy, let me know, and I will post it here.
    
    Rich (who_used_to_constantly_kill_editor_processes!)
    
641.7Axel says post it.LEROUF::STADTELMEYERChallenge the good!Tue Jan 12 1988 05:087
	Re: .6
        
        Come on, Rich,
        
        don't be shy, let us have your version. 
        
        	Axel
641.8Here's one in CRAINBO::LONGWhat does it mean - exact change?Tue Jan 12 1988 16:58181
    This has been working for me for a long time.  If you have any
    problems, please e-mail me.
    
    NOTE:  This program accounts for subprocesses of the current process,
    i.e. the one you are logging out.  If the current process has a
    subprocess, and THAT subprocess has a subprocess, then the returned
    count is still one.  This program does not recursively handle "sons
    of sons", so if it says you have one subprocess, you may in fact
    have more.  I've always found it adequate, however.
    
    To build:
    
      o extract this note.
      o cut on the dotted line.
      o write source to a file.
      o cc filename
      o link filename
      o define symbol lo*gout to point to the file and enjoy!
    
    ------------------cut here-----------------------------------------------
                      
    
/*----------------------------------------------------------------------------
LOGOUT.C --

  Utility called on logout; performs the following action:

      o Checks for subprocesses.  Informs you if there are any, and confirms
        logout.  This differentiates between subprocesses of the process
        you are logging out of, and subprocesses in your entire tree.

----------------------------------------------------------------------------*/

#include <stdio.h>
#include <time.h>
#include <ssdef.h>            /* system services stuff */
#include <descrip.h>
#include <jpidef.h>
#include <ctype.h>

#define PROGNAME   "LOGOUT : "

#define TRUE  1
#define FALSE 0

/*
 * define a record of process information.  will be filled in by $GETJPI.
 */

struct info_rec
  {
  long  subprocs;           /* # of subprocesses */
  long  len_subprocs;
  char  procnam [16];       /* process name */
  long  len_procnam;
  char  usernam [13];       /* username */
  long  len_usernam;
  };

/* -------------------- functions -------------------------------------- */

long get_process_info (profile)

struct info_rec *profile;

{

/* descriptor for use in system calls */
struct item 
  {
  short   size;
  short   item_code;
  char    *buffer_ptr;
  char    *buffer_length_ptr;
  };

int     i;
long    status;

struct {
  struct item process_prccnt;
  struct item process_procnam;
  struct item process_username;
  long  zero;
  } jpi = {
    04, JPI$_PRCCNT,     &profile->subprocs,   &profile->len_subprocs,
    16, JPI$_PRCNAM,     &profile->procnam,    &profile->len_procnam,
    12, JPI$_USERNAME,   &profile->usernam,    &profile->len_usernam,
    00L
    };

  /* 
   * ask the system for the info 
   */

  if ((status = SYS$GETJPI (0, 0, 0, &jpi, 0, 0, 0)) != SS$_NORMAL) 
    return (status);

  profile->procnam [profile->len_procnam] = '\0';

  /*
   * cut username at first blank.
   */

  for (i = 0; ((i <= 12) && (profile->usernam [i] != ' ')); i++) 
    {}

  profile->usernam [i] = '\0';

  return (status);

}

/* --------------- begin main program section ---------------------------- */

main ()

{

char response [10];
$DESCRIPTOR (do_cmd, "stop/identif=0");
long status;
long ttime;
struct tm *tm_rec_ptr;

/* process information record */
struct info_rec profile = {
  0L,                        /* # of subprocesses */
  0L,                        /* len */
  "               ",         /* process name */
  0L,                        /* len */
  "            ",            /* username */
  0L,                        /* len */
  };

  /* 
   * find out about the process 
   */

  if ((status = get_process_info (&profile)) != SS$_NORMAL) 
    {
    printf ("%s Unable to get the process information ($GETJPI)\n", PROGNAME);
    exit (status);
    }

  if (profile.subprocs > 0L) 
    {
    printf ("\nIndications are that you have %s running.\n",
            (profile.subprocs > 1L) ? "subprocesses" : "a subprocess");

    printf ("%s will be DESTROYED if you log out.\n",
            (profile.subprocs > 1L) ? "These" : "It");

    printf ("Do you want to log out anyway (y/[n])? ");

    fgets (response, 10, stdin);
    if (_toupper (*response) != 'Y') exit (SS$_NORMAL);  /* just leave */
    }

  /*
   * here is the place to put any clever message you would like to see
   * at logout.
   */

  ttime = time (NULL);
  tm_rec_ptr = localtime (&ttime);
  
  printf ("\n  %s logging out of process %s on %d-%d-%d at %d:%02d:%02d\n", 
           profile.usernam,
           profile.procnam,
           tm_rec_ptr->tm_mon + 1, tm_rec_ptr->tm_mday, tm_rec_ptr->tm_year,
           tm_rec_ptr->tm_hour, tm_rec_ptr->tm_min, tm_rec_ptr->tm_sec);

  /*
   * bye-bye
   */

  LIB$DO_COMMAND (&do_cmd);

}
    
641.9A simple LOGOUT.COMLEELA::MYEEOn the High Road to China...Mon Jan 18 1988 15:3518
    Simple but does the job for me.
    /Mike
    
------------------------cut here--------------------------------------
$
$ ! logout.com  - traps logout when active subprocess exist
$ ! Author: Michael K. Yee
$
$ if (f$getjpi("","PRCCNT") .eq. 0) then goto DONE
$ show proc/sub
$ write sys$output ""
$ inquire answer "WARNING: You still have active subprocess, logout? [N]"
$ if (answer) then goto DONE
$ exit
$DONE:
$ logout/brief
$ exit