|  |     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
 | 
|  |     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
 | 
|  |     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);
}
    
 |