List all processes which have at least 1 STCP device clone locked

Blue Bar separator

The stcp_device_lockers.cm macro produces a list of process that have at least 1 STCP device clone locked. The list is sorted based on the number of devices that the process has locked.

Why do you care?

Most of the time you don't, but on the rare occasions when the module reports that it has reached the STCP device clone limit it is nice to know what processes have the devices locked. It may be that everything is working correctly and you have just reached the configured limit. On the other hand most of the time when I have seen this it is due to one or a few processes consuming all the devices because of incorrect error handling. In these cases the faster you know which process(es) to kill the better.

The following shows how to run the macro and its output. The macro takes no arguments. Output consists of a number of rows starting with a number and then a user ID and process name. The number is a count of the number of STCP device clones that the process has locked. The list is sorted in descending order of the number of devices locked. In this case the login process of Noah.Davids.CAC has 4090 devices locked, chances are something is not working correctly.

stcp_device_lockers
  4090  Noah Davids.CAC (login)
    20  Overseer.System (osl daemon)
     5  Apache.SysAdmin (httpd)
     4  root.root (sshd)
     2  root.root (smbd)
     1  Noah Davids.SysAdmin (telnetd)
     1  Overseer.System (ftpd)
     1  Overseer.System (snmpd)
     1  root.root (httpd)
           Summary of STCP device lockers done on 13-01-18 at 16:07:05

The macro leaves two files in the current working directory. The first is the stcp_device_lockers file which is a list of each device and the corresponding output from the who_locked command.

d stcp_device_lockers

%azvos#m17_mas>SysAdmin>Noah_Davids>stcp_device_lockers  13-01-18 16:09:05 mdt

stcp.m17:
     Object is not locked.
stcp.m17_18684:
     Object is write locked by root.root (sshd) on module %azvos#m17 executing
          sshd.pm.
stcp.m17_2:
     Object is write locked by Overseer.System (ftpd) on module %azvos#m17
          executing ftpd.pm.
stcp.m17_3:
     Object is write locked by Overseer.System (snmpd) on module %azvos#m17
          executing snmpd.pm.
stcp.m17_5:
     Object is write locked by root.root (stcp_inetd) on module %azvos#m17
          executing inetd.pm.
stcp.m17_6:
     Object is write locked by root.root (stcp_inetd) on module %azvos#m17
          executing inetd.pm.
stcp.m17_7:
     Object is write locked by root.root (stcp_inetd) on module %azvos#m17
          executing inetd.pm.
--PAUSE--

The second is the stcp_devices_summary file which is just the macro's output convententy stored in a file.

Note 1: If two processes are run by the same user and have the same process name they will be grouped together.

Note 2: This macro executes 2 sorts. The first sort will have an entry for each STCP device clone on the system. Assuming that the system has hit the clone limit this can be up to 16000 entries. The second sort will have an entry for each unique USER.GROUP (PROCESS). It may take a few minutes to generate the report

Note 3: This macro makes extensive use of attach_default_output. If the macro aborts or you terminate it you may need to manually execute a detach_default_output

Note 4: It is possible that between the time that the list of devices is created and the time that the who_locked is done one or more of those devices will no longer exist. If that is the case you will get a "who_locked: The specified device name is not known to the system." message, just ignore it.

stcp_device_lockers.cm

& stcp_device_owners.cm begins here
&
& Version 1.0 13-01-18
& noah.davids@stratus.com
&
& This macro produces a list of processes which have at least 1 stcp device
& clone locked. The list is sorted based on the number of devices that the
& process has locked.
&
& This software is provided on an "AS IS" basis, WITHOUT ANY WARRANTY OR ANY
& SUPPORT OF ANY KIND. The AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES
& OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE.  This disclaimer
& applies, despite any verbal representations of any kind provided by the
& author or anyone else.
&
& make sure extraneous stuff isn't echoed into the results file
&if (process_type) = 'batch'
&then &do
set_ready -format off
&echo no_command_lines
&end     
&
&set_string LDEVICES (process_dir)>list_devices
&set_string SDEVICES (process_dir)>stcp_devices
&set_string LOCKEDBY (process_dir)>lockedby
&
& This file is the output from the who_locked of all the stcp devices. The
& reason it is not in the process_dir is so that you can run this macro
& as a started process and still be able to refer to this output.
&set_string WHOLOCKED stcp_device_lockers
&
& This will be the final output
&set_string SUMMARY stcp_devices_summary
&
&
& First we build a list of all streams device
attach_default_output &LDEVICES&
list_devices -type streams
detach_default_output
&
& Now filter the list to get another list of just stcp device clones.
display &LDEVICES& -match #stcp.(after (current_module) '#')  &+
    -output_path &SDEVICES& -no_header
&        
& For each of the stcp device clones find out who has them locked
& Note that  it is possible that the device is not locked or that the
& device is no longer than because the process which had it locked has
& closed it
attach_default_output &WHOLOCKED&
&set LINE 1
&label AGAIN
&set_string DEV (contents &SDEVICES& &LINE& -hold)
&if (end_of_file &SDEVICES&) = 0
&then &do
  who_locked &DEV&
  &set LINE (calc &LINE& + 1)
  &goto AGAIN
&end
detach_default_output
&
& Extract out the "object is' lines which should include the user ID and
& process name. At this point we don't care about which devices the process
& has locked.
display &WHOLOCKED& -match 'Object is' -output_path &LOCKEDBY& -no_header
&
& Sort all the who_locked lines.
sort &LOCKEDBY&
&
& Read through the sorted list. Start counting lines and increment if the
& current line is equal to the previous line. When the lines are not equal
& we know there has been a change and we can output the current count and the
& current line and reset the counter. Note that if two processes are run by
& the same user ID and have the same process name the counts will be combined
& since there is no way to tell them apart. We are starting at line three
& because the first line is blank and the second line is
& 'Object is not locked' from the who_locked of the parent stcp device which
& is never locked (just the clones are locked). The parens () and space
& characters are translated into brackets [] and underscore when the lines
& are read so that I don't have to worry about quoting the strings and having
& the system think that the process name is a command function. They are
& translated back when the count line is output. I also trim off a lot of
& extraneous text when the line is written leaving only the user ID and
& process name. The count is also right justified so sorting works.
&
attach_default_output &SUMMARY&
display_line '          ' Summary of STCP device lockers done &+
     on (date) at (time)

&set_string OLDLINE (translate (contents &LOCKEDBY& 2 -hold) '[_]' '( )')
&set LINE 3
&set PROCCOUNT 1
&label AGAIN2
&set_string WHOLINE (translate (contents &LOCKEDBY& &LINE& -hold) '[_]' '( )')
&if (end_of_file &LOCKEDBY&) = 0
&then &do
  &if &WHOLINE& = &OLDLINE& &then &do
       &set PROCCOUNT (calc &PROCCOUNT& + 1)
  &end
  &else &do
       &set_string TEMP &PROCCOUNT&
       &set TEMPLEN (length &TEMP&)
       display_line (substr '         ' 1 (calc 5 - &TEMPLEN&)) &TEMP& &+
         (translate (before (after &OLDLINE& 'locked_by') '_on') &+
           '( )' '[_]')
       &set_string OLDLINE &WHOLINE&
       &set PROCCOUNT 1
  &end
  &set LINE (calc &LINE& + 1)
  &goto AGAIN2
&end
detach_default_output
&
& Another sort - this time on the numerical count. It is an ascii sort so
& that the date and time line is not an exception.
sort &SUMMARY& -position_1 1 -length_1 6 -collation_1 descending_ascii
&
& We are done but the summary file is displayed automagically.
display &SUMMARY& -no_header
&
& stcp_device_owners.cm ends here



Blue Bar separator
This page was last modified on 13-01-18
mailbox Send comments and suggestions
to noah@noahdavids.org