Program RmDemo c c Author: Mark R. Vevle c X-Ray Crystallographic Core Facility c University of Alabama at Birmingham c SDB 13, 244B LHR c University Station c Birmingham, Alabama 35294 c (205) 934 - 2212/2149 c c Description: RmDemo - A dynamic, user information, display program. c c This program is terminal independent, but can use c special keys on the VT100 and VT200 series terminals. c Keys can be redefined/added by modifing the c Process_Input routine. c c Function: o To provide detailed information about users on c the system. c c Disclaimer/rights: This software is in the public domain and is c provided free though DECUS or other channels. The c information in this software is subject to change c without notice and should not be construed as a c commitment by the author or his employer. The author c and his employer assumes no responsibility for the c use, the correctness, or the reliability of this c software. THIS SOFTWARE IS PROVIDED AS IS. c c Environment: VAX/VMS V3.0 or later c c Privledges Needed: ALTPRI, CMKRNL, and WORLD c c ALTPRI - so it can boost it's own priority (not c required). c CMKRNL - to get the idle times from the UCB's. c WORLD - so it can do GETJPI's on all processes. c c Note: CMKRNL is required. If this program is run c without CMKRNL privledge it will bomb out. c c Modifications: c c V1.0 - The original version c c V1.1 - Added pages of display and increased number c of processes that can be displayed. The c maximum number of process that can be c displayed now is 128 ( 19 per page with c 6+ pages ). MRV. June 10, 1984 c c V1.2 - Corrected overflow on internal reads for c the display of page faults in routine c Process_Numbers when the number of page c faults are larger than 999,999. The field c is filled with "*". MRV. August 24, 1984 c c V1.3 - Corrected overflow on internal reads for c the display of CPU times. When the number c CPU hours is to large the field is filled c with "*". MRV. November 12, 1984 c c V1.4 - Modified the rmd_ctrl_exit routine to force c an immediate exit on ^Y and on ^C. c c - Modified the modify_sleep_time routine so c that wake ups can be changed while c hibernating. This allows one to get out of c a long hibernation. c c - Modified the process_input routine so that c the sleep flag is set to 1 when the exit c flag is set. This allows for a faster exit c when the sleep time is large. c c - Added RMDEMO version number to the display. c c - MRV. December 27, 1984. c c V1.5 - Modified the Getjpi_Setup routine so that c the correct process size is reported. ie. c process size is Process_Page_Count + c Global_Page_Count. c c - MRV. January 16, 1985. integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c data user_table / 384* 0 / c logical*1 sleep_time, sleeping c common /hiber/ sleep_time, sleeping c character*74 screen( 128 ) c common /disply/ screen c data screen / 128* ' ' / c character*128 image_name character*15 process_name, user_name character*7 terminal c common /jpistr/ image_name, process_name, terminal, 1 user_name c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c integer*4 pid, io_status( 2 ), getjpi_flag / 1 / integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c character*8 system_version character*3 system_type c common /syival/ system_version, system_type c integer*4 getsyi_list( 9 ), getsyi_flag / 2 / c common /syiprm/ getsyi_list, getsyi_flag c integer*4 my_current_priority/ 4 /, my_base_priority/ 4 / c common /curpri/ my_current_priority, my_base_priority c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number / 1 /, page_index / 1 / c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c integer*4 input_code, input_flag / 3 /, input_iosb( 2 ) integer*2 tt_channel logical*1 input_buffer( 20 ) c common /inqio/ input_code, input_flag, input_iosb, 1 tt_channel, input_buffer c integer*4 ctrl_status c jbctl_flag = .false. c c *** Set up QIO for input. c call setup_qio c c *** Disable Control_Y c ctrl_status = Lib$Disable_Ctrl( '02000000'X ) if(.not.ctrl_status) then call errrec(ctrl_status) STOP '-RMD-F-DISABLEFAIL, disable ctrl_y failed.' end if c c *** Boost my priority by 2 c call modify_priority_by( 2 ) c c *** Schedual wakeups in 3 second intervals to begin with. c sleeping = .true. sleep_time = 3 sleep_flag = .True. Call Modify_Sleep sleeping = .false. c c *** Setup GETJPI request c call setup_getjpi c c *** Get System information c call get_system_info c c *** Go into the display loop c user_flag = .true. c call display_loop c c *** finished c call modify_priority_by( -( my_current_priority - my_base_priority ) ) c ctrl_status = Lib$Enable_Ctrl( '02100000'X ) if(.not.ctrl_status) then call errrec(ctrl_status) STOP '-RMD-W-ENABLEFAIL, enable ctrl_y failed.' end if end subroutine setup_qio c include '($iodef)' c integer*4 input_code, input_flag, input_iosb( 2 ) integer*2 tt_channel logical*1 input_buffer( 20 ) c common /inqio/ input_code, input_flag, input_iosb, 1 tt_channel, input_buffer c integer*4 iassign_stat, Sys$Assign, Sys$Qio integer*4 ctrly_code, ctrlc_code, qio_stat c external rmd_ctrl_exit c c *** Get a channel to the terminal c iassign_stat = Sys$Assign( 'TT', tt_channel, , ) if ( .not. iassign_stat ) then call errrec( iassign_stat ) stop 'RMD-F-ASSIGNFAIL, failed to assign channel to terminal' end if c c *** Setup the QIO function codes c input_code = jior( IO$_Readlblk, jior( IO$M_NoEcho, 1 jior( IO$M_Cvtlow, 1 jior( IO$M_Escape, 1 jior( IO$M_TrmNoEcho, 1 IO$M_NoFiltr ) ) ) ) ) ctrly_code = jior( IO$_SetMode, IO$M_CtrlyAst ) ctrlc_code = jior( IO$_SetMode, IO$M_CtrlcAst ) c c *** Specify Ast routines for Control_Y and Control_C c qio_stat = Sys$Qio( , %val( tt_channel ), %val( ctrly_code ), 1 , , , rmd_ctrl_exit, , , , , ) qio_stat = Sys$Qio( , %val( tt_channel ), %val( ctrlc_code ), 1 , , , rmd_ctrl_exit, , , , , ) c c *** Issue first read c call get_input c return end subroutine rmd_ctrl_exit c Character*1 esc c integer*4 my_current_priority, my_base_priority integer*4 ctrl_status c common /curpri/ my_current_priority, my_base_priority c c *** restore cursor c esc = char( 27 ) Call Lib$Put_Screen( esc // '[?25h', 1, 1 ) Call Lib$Erase_Page( 1, 1 ) c Call Modify_Priority_By( -( my_current_priority - my_base_priority ) ) c ctrl_status = Lib$Enable_Ctrl( '02100000'X ) if(.not.ctrl_status) then call errrec(ctrl_status) STOP '-RMD-W-ENABLEFAIL, enable ctrl_y failed.' end if c Stop 'Exit' end subroutine get_input c integer*4 input_code, input_flag, input_iosb( 2 ) integer*2 tt_channel logical*1 input_buffer( 20 ) c common /inqio/ input_code, input_flag, input_iosb, 1 tt_channel, input_buffer c integer*4 qio_stat, Sys$Qio c external process_input c qio_stat = Sys$Qio( %val( input_flag ), %val( tt_channel ), 1 %val( input_code ), input_iosb, 1 process_input, , input_buffer, 1 %val( 20 ), , , , ) c return end subroutine process_input c integer*4 input_code, input_flag integer*2 tt_channel, input_iosb( 4 ) logical*1 input_buffer( 20 ) c common /inqio/ input_code, input_flag, input_iosb, 1 tt_channel, input_buffer c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number, page_index c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c logical*1 sleep_time, sleeping c common /hiber/ sleep_time, sleeping c character*20 command_line character*1 esc / 27 / c integer*2 terminator c equivalence( command_line, input_buffer ) c terminator = input_iosb( 3 ) c If ( exit_flag ) return c If ( ( terminator .eq. 5 ) .or. ( terminator .eq. 26 ) ) then exit_flag = .true. sleep_time = 1 sleep_flag = .true. call modify_sleep return Else If ( terminator .eq. 1 ) then display_all_flag = .not. display_all_flag Else If ( ( ( terminator .eq. 21 ) .and. 1 ( process_flag ) ) .or. 1 ( terminator .eq. 16 ) ) then process_flag = .not. process_flag Else If ( ( terminator .eq. 21 ) .or. 1 ( index( command_line, esc // '[4~' ) .ne. 0 ) ) then user_flag = .not. user_flag process_flag = .false. Else If ( terminator .eq. 23 ) then redraw_flag = .true. Else If ( ( terminator .eq. 31 ) .or. 1 ( index( command_line, esc // 'OQ' ) .ne. 0 ) .or. 1 ( index( command_line, esc // '[28~' ) .ne. 0 ) ) then help_flag = .true. Else If ( index( command_line, esc // '[A' ) .ne. 0 ) then call modify_priority_by( 1 ) Else If ( index( command_line, esc // '[B' ) .ne. 0 ) then call modify_priority_by( -1 ) Else If ( index( command_line, esc // '[C' ) .ne. 0 ) then sleep_time = sleep_time + 1 sleep_flag = .true. Call modify_sleep Else If ( index( command_line, esc // '[D' ) .ne. 0 ) then sleep_time = sleep_time - 1 sleep_flag = .true. Call modify_sleep Else If ( index( command_line, esc // '[2~' ) .ne. 0 ) then display_all_flag = .true. Else If ( index( command_line, esc // '[3~' ) .ne. 0 ) then display_all_flag = .false. Else If ( ( terminator .eq. 14 ) .or. 1 ( index( command_line, esc // '[6~' ) .ne. 0 ) ) then If ( page_number .lt. 7 ) then page_number = page_number + 1 page_index = 19 * ( page_number - 1 ) + 1 Else page_number = 1 page_index = 1 End If Else If ( ( terminator .eq. 2 ) .or. 1 ( index( command_line, esc // '[5~' ) .ne. 0 ) ) then If ( page_number .gt. 1 ) then page_number = page_number - 1 page_index = 19 * ( page_number - 1 ) + 1 Else page_number = 7 page_index = 115 End If Else unknown_flag = .true. End If c call get_input c return end subroutine modify_sleep c logical*1 sleep_time, sleeping c common /hiber/ sleep_time, sleeping c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number, page_index c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c integer*4 binary_time( 2 ), Sys$BinTim, Sys$SchdWk integer*4 bin_stat, wakeup_stat, Sys$CanWak c character*16 delta_time character*2 sleep c 10 format('0000 00:00:',i2,'.00') 20 format( i2 ) c c *** Set up continous wakeups in delta_time intervals c If ( sleep_time .gt. 59 ) then sleep_time = 1 Else If ( sleep_time .lt. 1 ) then sleep_time = 59 End If c If ( sleeping ) then c write ( delta_time, 10 ) sleep_time c ican_stat = Sys$CanWak( , ) bin_stat = Sys$BinTim( delta_time, binary_time ) wakeup_stat = Sys$SchdWk( , , binary_time, binary_time ) If ( .not. wakeup_stat ) then call errrec( wakeup_stat ) stop ' ' End If c If ( .not. Exit_Flag ) Then write( sleep, 20 ) sleep_time if ( sleep_time .lt. 10 ) sleep( : 1 ) = char( 0 ) Call Lib$Put_Screen( sleep // ' seconds. ' 1 // char( 13 ) // char( 10 ), 2, 34 ) c Call Lib$Set_Cursor ( 3, 1 ) End If c sleep_flag = .false. c End If c Return End subroutine display_loop c character*128 image_name character*15 process_name, user_name character*7 terminal c common /jpistr/ image_name, process_name, terminal, 1 user_name c logical*1 sleep_time, sleeping c common /hiber/ sleep_time, sleeping c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c integer*4 getjpi_flag, pid, io_status( 2 ) integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c character*74 screen( 128 ) c common /disply/ screen c character*8 system_version character*3 system_type c common /syival/ system_version, system_type c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number, page_index c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c integer*4 job_control_time( 2 ) c common /base/ job_control_time c integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c character*23 current_date_time character*10 up_time character*9 day_of_week character*5 get_idle character*4 idle_time character*2 sleep, act_proc character*1 esc / 27 /, cr / 13 /, lf / 10 / character*1 null / 0 /, curr_page c integer*4 Lib$Put_Screen, output_status, column integer*4 Lib$Set_Scroll, Lib$Erase_Page, Sys$Hiber integer*4 total_processes c 10 Format ( i2 ) 15 Format ( i1 ) c idle_time = '100%' do while ( .not. exit_flag ) iret_stat = Lib$Date_Time( current_date_time ) call get_weekday( day_of_week, 0, len ) column = 25 + len output_status = Lib$Erase_Page( 1, 1 ) output_status = Lib$Put_Screen( esc // '[?25l', 1, 1 ) output_status = Lib$Put_Screen( 'VAX 11/' // system_type // 1 ', VMS ' // system_version( : 4 ) // '. ' // 1 day_of_week( :len ) // ', ' // 1 current_date_time // ', ' // 1 idle_time // ' idle.' // cr // lf, 1, 1 ) output_status = Lib$Put_Screen( ' Page 1 ' // cr // lf, 1 1, 73, 3) output_status = Lib$Set_Scroll( 5, 24 ) output_status = Lib$Put_Screen( 'Process_Name ' // 1 'Image ' // 1 'Term ' // 1 'Prior ' // 1 'State ' // 1 'Log ' // 1 'Fl ' // 1 'Size ' // 1 'Pg_Flt ' // 1 ' Cpu_Time ' // 1 '%Cpu ' // 1 'Idle' // cr // lf, 4, 1, 2 ) c redraw_flag = .false. c do while ( ( .not. exit_flag ) .and. ( .not. redraw_flag ) ) c call get_users( total_processes, icount, idle_time ) call get_idle_times call get_up_time( up_time ) c write( act_proc, 10 ) total_processes write( sleep, 10 ) sleep_time write( curr_page, 15 ) page_number if ( sleep_time .lt. 10 ) sleep( : 1 ) = null if ( total_processes .lt. 10 ) act_proc( : 1 ) = null c iret_stat = Lib$Date_Time( current_date_time ) c output_status = Lib$Put_Screen( current_date_time // ', ' // 1 idle_time // ' idle. ' // cr 1 // lf, 1, column ) output_status = Lib$Put_Screen( ' Page ' // curr_page // ' ' 1 // cr // lf, 1, 73, 3) output_status = Lib$Put_Screen( 'Up Time: ' // up_time 1 // '. ', 2, 1 ) Call Lib$Put_Screen ( 'Update Rate: ' // sleep 1 // ' seconds. ', 2, 21 ) Call Lib$Put_Screen ( ' Active Processes: ' 1 // act_proc // '. ', 2, 47 ) Call Lib$Put_Screen ( 'RMD V2.0' // cr // lf, 2, 73 , 8 ) c j = 5 i = page_index c Do While ( ( j .lt. 24 ) .and. ( i .le. icount ) ) output_status = Lib$Put_Screen( screen( i ) // ' ' // 1 get_idle( screen( i )( 24: 24 ), i ) // 1 cr // lf, j, 1 ) i = i + 1 j = j + 1 End Do c output_status = Lib$Erase_Page( j, 1 ) c If ( icount .ge. i ) 1 output_status = Lib$Put_Screen( ' More ' // cr, 24, 37, 6 ) c if ( help_flag ) then call help( j ) help_flag = .false. unknown_flag = .false. else if ( unknown_flag ) then call alert( j ) unknown_flag = .false. end if c c *** wait for a wakeup call c sleeping = .True. if ( sleep_flag ) call modify_sleep Call Lib$Set_Cursor ( 3, 1 ) irest_stat = sys$hiber() sleeping = .False. end do end do c c *** restore cursor c output_status = Lib$Put_Screen( esc // '[?25h', j, 1 ) output_status = Lib$Erase_Page( j, 1 ) c return end Character*5 Function Get_Idle( terminal, Index ) c Call a kernel mode routine which makes a table of idle times c for allocated terminals Parameter max_units = 128 Integer*4 I_Idle, I_hr, I_min Integer*4 PID, Index c integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c character*1 terminal c Get_Idle = ' ' c c If ( ( terminal .le. 'Q' ) .or. ( terminal .ge. 'U' ) ) Return c c PID = user_index( Index ) c c Get_Idle = ' ###' c c Do ii = 1, max_units c If ( pid_table( ii ) .eq. 0 ) Return c Type 50, PID, pid_Table( ii ) c If ( PID .eq. pid_table( ii ) ) then c I_Idle = idle_table( ii ) c Go to 200 c End if c End do c c Get_Idle = ' &&&' c Return c 200 Continue Get_Idle = ' ???' If ( I_Idle .le. 0 ) Return I_min = I_Idle / 60 I_hr = I_Min / 60 I_Min = I_Min - ( 60 * I_hr ) Write ( Get_Idle, 1000, Err=300 ) I_hr, I_Min If ( I_hr .eq. 0 ) then Get_Idle( 1: 3 ) = ' ' If ( I_Min .le. 0 ) Get_Idle = ' .' Else If ( Get_Idle( 4: 4 ) .eq. ' ' ) Get_Idle( 4: 4 ) = '0' End if 300 Return c 1000 Format(I2,':',I2) c End Subroutine Get_Idle_Times c Call a kernel mode routine which makes a table of idle times c and PIDs for allocated terminals Parameter max_units = 128 c integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c IStatus = Idle( idle_table, pid_table, max_units ) If ( .not. IStatus ) then Call errrec( IStatus ) stop ' Error in Routine: Get_Idle_Times ' end if Return End subroutine get_up_time( up_time ) c character*10 up_time character*1 null / 0 / c integer*4 job_control_time( 2 ) c common /base/ job_control_time c integer*4 current_time( 2 ), Sys$GetTim, tim_stat integer*4 Sys$AscTim, result( 2 ) c tim_stat = Sys$GetTim( current_time ) tim_stat = Lib$Subx( job_control_time, current_time, result ) tim_stat = Sys$AscTim( , up_time, result ) c if ( up_time( : 3 ) .eq. ' ' ) then up_time( : 3 ) = null // null // null else if ( up_time( : 2 ) .eq. ' ' ) then up_time( : 2 ) = null // null else up_time( : 1 ) = null end if c return end subroutine help( start ) c character*10 sp / ' ' / character*1 cr / 13 /, lf / 10 / integer*4 start, out_stat, Sys$Hiber c i = start c out_stat = Lib$Put_Screen( ' Rmdemo Help ', i + 1, 33, 3 ) out_stat = Lib$Put_Screen( cr // lf // lf // sp ) out_stat = Lib$Put_Screen( ' ^A ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Switch for adding/removing' // 1 ' system processes to the display.' // 1 cr // lf // sp ) out_stat = Lib$Put_Screen( ' or ', , 10, 2 ) out_stat = Lib$Put_Screen( ' use Insert and Remove ( VT220 only ).' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^B ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Previous screen' // 1 cr // lf // sp ) out_stat = Lib$Put_Screen( ' or ', , 10, 2 ) out_stat = Lib$Put_Screen( ' use Prev_Screen Key ( VT220 only ).' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^E ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Exit.' // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^N ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Next Screen' // 1 cr // lf // sp ) out_stat = Lib$Put_Screen( ' or ', , 10, 2 ) out_stat = Lib$Put_Screen( ' use Next_Screen Key ( VT220 only ).' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^P ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Switch for showing/removing PIDs.' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^U ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Switch from username to process' // 1 ' name and back.' // cr // lf // sp ) out_stat = Lib$Put_Screen( ' or ', , 10, 2 ) out_stat = Lib$Put_Screen( ' use the SELECT key ( VT220 only ).' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^W ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Redraw entire screen.' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^Z ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Exit.' // cr // lf // sp ) out_stat = Lib$Put_Screen( ' ^? ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Help or use a keyboard HELP key (' // 1 ' ie. HELP or PF2 ). ' 1 // cr // lf // lf // sp ) out_stat = Lib$Put_Screen( ' Up Arrow ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Increase your base priority. ' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' Dn Arrow ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Decrease your base priority. ' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' Rg Arrow ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Increase time between screen updates.' 1 // cr // lf // sp ) out_stat = Lib$Put_Screen( ' Lf Arrow ', , 10, 2 ) out_stat = Lib$Put_Screen( ' Decrease time between screen updates.') c out_stat = Sys$Hiber() out_stat = Sys$Hiber() c return end subroutine alert ( start ) c integer*4 start, out_stat, Sys$Hiber c i = start c out_stat = Lib$Put_Screen( 1 ' -- Type ^? or any keyboard HELP key for Help -- ', 1 i, 15, 6 ) c out_stat = Sys$Hiber() c return end Subroutine get_users( total_processes, user_count, idle_time ) c c *** include system return codes c include '($ssdef)' c integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c character*74 screen( 128 ) c common /disply/ screen c character*128 image_name character*15 process_name, user_name character*7 terminal c common /jpistr/ image_name, process_name, terminal, 1 user_name c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count , 1 Process_Index c integer*4 io_status( 2 ), getjpi_flag, pid integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number, page_index c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c integer*4 job_control_time( 2 ) c common /base/ job_control_time c character*4 idle_time c integer*4 jpi_status, user_count, sys$waitfr integer*4 Sys$Getjpi, total_processes integer*2 percent_idle c 10 format( i3,'%' ) c total_processes = 0 percent_idle = 100 pid = -1 user_count = 0 c c *** get first process c jpi_status = Sys$Getjpi( %val( getjpi_flag ), pid, , 1 getjpi_list, io_status, , ) c do while ( jpi_status .ne. SS$_NoMoreProc ) c total_processes = total_processes + 1 user_count = user_count + 1 c c *** Wait for the Getjpi request to complete c if ( jpi_status ) iwait_stat = sys$waitfr( %val( getjpi_flag ) ) c c *** Calculate amount of CPU time c call cpu_usage( user_count, percent_idle ) c If ( .not. jbctl_flag ) then If ( ( Process_name( 1: 11 ) .eq. 'JOB_CONTROL' ) .and. 1 ( index( image_name, 'JOBCTL' ) .ne. 0 ) ) then job_control_time( 1 ) = login_time( 1 ) job_control_time( 2 ) = login_time( 2 ) jbctl_flag = .true. End If End If c if ( ( .not. display_all_flag ) .and. 1 ( ( ( user_name( 1: 6 ) .eq. 'SYSTEM' ) .and. 1 ( terminal_length .eq. 0 ) .and. 1 ( .not. bjtest( process_status, 14 ) ) ) .or. c 1 ( user_name( 1: 11 ) .eq. 'JOB_CONTROL' ) .or. 1 ( user_name( 1: 6 ) .eq. 'DECNET' ) ) ) then user_count = user_count - 1 else c c *** Now process the strings c call process_strings( user_count ) c c *** Now process the numerics c call process_numbers( user_count ) c end if c c *** Get the next process c jpi_status = Sys$Getjpi( %val( getjpi_flag ), pid, , 1 getjpi_list, io_status, , ) c c *** Keep going c end do c if ( percent_idle .le. 0 ) then idle_time = ' 0%' else if ( percent_idle .gt. 100 ) then idle_time = '???%' else write( idle_time, 10 ) percent_idle end if c return end Subroutine Process_numbers( row ) c character*74 screen( 128 ) c common /disply/ screen c integer*4 io_status( 2 ), getjpi_flag, pid integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c c integer*4 row, cpu_min, cpu_sec, cpu_hou c c *** Process state table c character*5 Find_State( 14 ) c data Find_State /'colpg','mwait','cef ','pfw ','lef ','lefo ', 1 'hib ','hibo ','susp ','suspo','fpg ','com ', 1 'como ','cur ' / c 10 format( i2, '/', i ) 20 format( i2 ) 30 format( i4 ) 40 format( i6 ) 50 format( i3,':',i2.2,':',i2.2 ) c i = row j = 1 if ( base_priority .gt. 9 ) j = 2 c screen( i )( 36: 40 ) = Find_State( process_state ) if ( process_state .eq. 2 ) return write( screen( i )( 30: 34 ), 10 ) current_priority, base_priority write( screen( i )( 46: 47 ), 20 ) ( file_quota - 1 remaining_file_quota ) call get_weekday( screen( i )( 42: 44 ), login_time, j ) write( screen( i )( 49: 52 ), 30 ) page_count + Gbl_Page_Count write( screen( i )( 54: 59 ), 40, iostat=ios ) page_faults cpu_sec = cpu_time / 100 cpu_min = cpu_sec / 60 cpu_sec = cpu_sec - ( 60 * cpu_min ) cpu_hou = cpu_min / 60 cpu_min = cpu_min - ( 60 * cpu_hou ) write( screen( i )( 61: 69 ), 50 ) cpu_hou, cpu_min, cpu_sec if ( cpu_hou .eq. 0 ) then screen( i )( 61: 64 ) = ' ' if ( cpu_min .lt. 10 ) screen( i )( 65: 65 ) = ' ' end if c c *** Process status flags c if ( bjtest( process_status, 20 ) ) then screen( i )( 24: 28 ) = 'NOATH' else if ( bjtest( process_status, 15 ) ) then screen( i )( 24: 28 ) = 'NOACNT' else if ( terminal_length .eq. 0 ) then if ( bjtest( process_status, 14 ) ) then screen( i )( 24: 28 ) = 'batch' else if ( bjtest( process_status, 4 ) ) then screen( i )( 24: 28 ) = 'noswp' end if end if c return end Subroutine Process_strings( row ) c character*74 screen( 128 ) c common /disply/ screen c character*128 image_name character*15 process_name, user_name character*7 terminal c common /jpistr/ image_name, process_name, terminal, 1 user_name c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c integer*4 io_status( 2 ), getjpi_flag, pid integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c logical*1 display_all_flag, exit_flag, user_flag logical*1 process_flag, redraw_flag, help_flag logical*1 unknown_flag, sleep_flag, jbctl_flag logical*1 page_number, page_index c common /flags/ display_all_flag, exit_flag, user_flag, 1 process_flag, redraw_flag, help_flag, 1 unknown_flag, sleep_flag, jbctl_flag, 1 page_number, page_index c integer*4 row c 10 format ( Z8.8,' ' ) c i = row c if ( process_flag ) then write( screen( i )( 1: 12 ), 10 ) process_id else if ( user_flag ) then call convert( user_name( : user_length ), screen( i )( 1: 12 ) ) else screen( i )( 1: 12 ) = process_name( : process_length ) end if c if ( terminal_length .gt. 0 ) then screen( i )( 24: 28 ) = terminal( : terminal_length ) else screen( i )( 24: 28 ) = ' ' end if c if ( image_length .ne. 0 ) then j = index( image_name, ']' ) + 1 Do While ( j .gt. 1 ) image_name = image_name( j : ) j = index( image_name, ']' ) + 1 End Do image_name = image_name( : index( image_name, '.' ) - 1 ) call convert( image_name( :9 ), screen( i )( 14: 22 ) ) else if ( process_state .ne. 2 ) then screen( i )( 14: 22 ) = ' ' end if c return end Subroutine cpu_usage( row, percent_idle ) c integer*4 user_table( 3, 128 ), pid_table( 128 ) integer*4 idle_table( 128 ), user_index( 128 ) c common /usrtbl/ user_table, user_index, pid_table, 1 idle_table c character*74 screen( 128 ) c common /disply/ screen c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c integer*4 row, elapsed_time( 2 ), cpu_used integer*4 old_cpu_time, percent_cpu c integer*2 user_ptr integer*2 percent_idle c 10 format( i3,'%') c user_ptr = Process_Index user_index( row ) = Process_id c c *** Get elapsed time c if ( user_table( 1, user_ptr ) .eq. 0 ) then itimer_stat = Lib$Init_Timer( user_table( 1, user_ptr ) ) if ( .not. itimer_stat ) call errrec( itimer_stat ) user_table( 3, user_ptr ) = cpu_time screen( row )( 71: 74 ) = ' 0%' else itimer_stat = Lib$Stat_Timer( 1, elapsed_time, user_table( 1, 1 user_ptr ) ) itimer_stat = Lib$Init_Timer( user_table( 1, user_ptr ) ) if ( process_state .ne. 2 ) then old_cpu_time = user_table( 3, user_ptr ) user_table( 3, user_ptr ) = cpu_time cpu_used = ( cpu_time - old_cpu_time ) * 100 if ( cpu_used .gt. 0 ) then percent_cpu = elapsed_time( 1 ) / 100000 percent_cpu = cpu_used / percent_cpu percent_idle = percent_idle - percent_cpu write( screen( row )( 71: 74 ), 10 ) percent_cpu else screen( row )( 71: 74 ) = ' 0%' end if else user_table( 1, user_ptr ) = 0 screen( row )( 71: 74 ) = ' 0%' end if end if c c return end subroutine get_weekday( day, time, len ) c character day*(*) character*9 day_table( 0:6 ) c logical*1 size( 0:6 ) c integer*4 time( 2 ), len, ptr c data day_table / 'Wednesday', 'Thursday ', 'Friday ', 'Saturday ', 1 'Sunday ', 'Monday ', 'Tuesday ' / data size / 9, 8, 6, 8, 6, 6, 7 / c if ( time( 1 ) .eq. 0 ) then iday_stat = Lib$Day( iday ) else iday_stat = Lib$Day( iday, time ) end if c ptr = Mth$Jmod( iday, 7 ) day = day_table( ptr ) len = size ( ptr ) c return end subroutine get_system_info c integer*4 pid, io_status( 2 ), getjpi_flag integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c character*8 system_version character*3 system_type c common /syival/ system_version, system_type c integer*4 getsyi_list( 9 ), getsyi_flag c common /syiprm/ getsyi_list, getsyi_flag c integer*4 sys$getsyi, getsyi_status, sys$waitfr integer*4 waitfr_status c character*3 versions( 4 ) c data versions / '780', '750', '730', '7VV' / c getsyi_status = sys$getsyi( %val( getsyi_flag ), , , 1 getsyi_list, , , ) c if( getsyi_status ) then waitfr_status = sys$waitfr( %val( getsyi_flag ) ) if( .not. waitfr_status ) call errrec( waitfr_status ) else call errrec( getsyi_status ) end if c system_type = versions( type_value ) c return end subroutine modify_priority_by( amount ) c integer*4 amount integer*4 sys$setpri, return_status integer*4 my_current_priority, my_base_priority c common /curpri/ my_current_priority, my_base_priority c my_current_priority = my_current_priority + amount c if ( my_current_priority .lt. 1 ) then my_current_priority = 31 else if ( my_current_priority .gt. 31 ) then my_current_priority = 1 end if c return_status = sys$setpri( , , %val( my_current_priority ), ) c if ( .not. return_status ) then call errrec( return_status ) end if c return end subroutine convert( in, out ) c c *** routine to convert uppercase characters to lowercase c character in*(*), out*(*) character*26 upper, lower c integer*4 Str$Translate, iret_stat c upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' lower = 'abcdefghijklmnopqrstuvwxyz' c out( 1:1 ) = in( 1:1 ) iret_stat = Str$Translate( out( 2: ), in( 2: ), lower, upper ) c 10 return end subroutine setup_getjpi c c *** Job/Process information request type codes *** c include '($jpidef)' c character*128 image_name character*15 process_name, user_name character*7 terminal c common /jpistr/ image_name, process_name, terminal, 1 user_name c integer*4 remaining_file_quota, file_quota integer*4 login_time( 2 ), process_id integer*4 current_priority, base_priority integer*4 process_state, process_status integer*4 cpu_time, page_count integer*4 page_faults, Gbl_Page_Count Integer*4 Process_Index c common /jpival/ remaining_file_quota, file_quota, 1 login_time, process_id, 1 current_priority, base_priority, 1 process_state, process_status, 1 cpu_time, page_count, 1 page_faults, Gbl_Page_Count, 1 Process_Index c integer*4 getjpi_flag, pid, io_status( 2 ) integer*4 getjpi_list( 54 ), image_length integer*4 process_length, terminal_length integer*4 user_length, version_length integer*4 type_value c common /jpiprm/ getjpi_flag, pid, getjpi_list, io_status, 1 image_length, process_length, terminal_length, 1 user_length, version_length, type_value c character*8 system_version character*3 system_type c common /syival/ system_version, system_type c integer*4 getsyi_list( 9 ), getsyi_flag c common /syiprm/ getsyi_list, getsyi_flag c integer*2 short_list( 2, 54 ), sys_list( 2, 9 ) c equivalence( getjpi_list, short_list ) equivalence( getsyi_list, sys_list ) c c *** Set up the JPI request (never changes) *** c c *** Current Priority short_list( 1, 1 ) = 4 short_list( 2, 1 ) = jpi$_pri getjpi_list( 2 ) = %loc( current_priority ) getjpi_list( 3 ) = 0 c *** Base Priority short_list( 1, 4 ) = 4 short_list( 2, 4 ) = jpi$_prib getjpi_list( 5 ) = %loc( base_priority ) getjpi_list( 6 ) = 0 c *** Open file count short_list( 1, 7 ) = 4 short_list( 2, 7 ) = jpi$_filcnt getjpi_list( 8 ) = %loc( remaining_file_quota ) getjpi_list( 9 ) = 0 c *** Image Name short_list( 1, 10 ) = 128 short_list( 2, 10 ) = jpi$_imagname getjpi_list( 11 ) = %loc( image_name ) getjpi_list( 12 ) = %loc( image_length ) c *** Login Time short_list( 1, 13 ) = 8 short_list( 2, 13 ) = jpi$_logintim getjpi_list( 14 ) = %loc( login_time ) getjpi_list( 15 ) = 0 c *** Process Name short_list( 1, 16 ) = 15 short_list( 2, 16 ) = jpi$_prcnam getjpi_list( 17 ) = %loc( process_name ) getjpi_list( 18 ) = %loc( process_length ) c *** Current State short_list( 1, 19 ) = 4 short_list( 2, 19 ) = jpi$_state getjpi_list( 20 ) = %loc( process_state ) getjpi_list( 21 ) = 0 c *** Terminal short_list( 1, 22 ) = 7 short_list( 2, 22 ) = jpi$_terminal getjpi_list( 23 ) = %loc( terminal ) getjpi_list( 24 ) = %loc( terminal_length ) c *** User name short_list( 1, 25 ) = 12 short_list( 2, 25 ) = jpi$_username getjpi_list( 26 ) = %loc( user_name ) getjpi_list( 27 ) = %loc( user_length ) c *** File quota short_list( 1, 28 ) = 4 short_list( 2, 28 ) = jpi$_fillm getjpi_list( 29 ) = %loc( file_quota ) getjpi_list( 30 ) = 0 c *** Process status flags short_list( 1, 31 ) = 4 short_list( 2, 31 ) = jpi$_sts getjpi_list( 32 ) = %loc( process_status ) getjpi_list( 33 ) = 0 c *** Process identification short_list( 1, 34 ) = 4 short_list( 2, 34 ) = jpi$_pid getjpi_list( 35 ) = %loc( process_id ) getjpi_list( 36 ) = 0 c *** Cpu time short_list( 1, 37 ) = 4 short_list( 2, 37 ) = jpi$_cputim getjpi_list( 38 ) = %loc( cpu_time ) getjpi_list( 39 ) = 0 c *** Page count short_list( 1, 40 ) = 4 short_list( 2, 40 ) = jpi$_ppgcnt getjpi_list( 41 ) = %loc( page_count ) getjpi_list( 42 ) = 0 c *** Count of page faults short_list( 1, 43 ) = 4 short_list( 2, 43 ) = jpi$_pageflts getjpi_list( 44 ) = %loc( page_faults ) getjpi_list( 45 ) = 0 c *** Global Page Count short_list( 1, 46 ) = 4 short_list( 2, 46 ) = jpi$_GpgCnt getjpi_list( 47 ) = %loc( Gbl_Page_Count ) getjpi_list( 48 ) = 0 c *** Process Index short_list( 1, 49 ) = 4 short_list( 2, 49 ) = Jpi$_Proc_Index getjpi_list( 50 ) = %loc( Process_Index ) getjpi_list( 51 ) = 0 c *** Mark end of options getjpi_list( 52 ) = 0 getjpi_list( 53 ) = 0 getjpi_list( 54 ) = 0 c c *** Define the getsyi item list for system version c sys_list( 1, 1 ) = 8 sys_list( 2, 1 ) = 256 getsyi_list( 2 ) = %loc( system_version ) getsyi_list( 3 ) = %loc( version_length ) c *** Mark end of options sys_list( 1, 4 ) = 4 sys_list( 2, 4 ) = 512 getsyi_list( 5 ) = %loc( type_value ) getsyi_list( 6 ) = 0 c getsyi_list( 7 ) = 0 getsyi_list( 8 ) = 0 getsyi_list( 9 ) = 0 c return end