From: Lyle West [arf@ourtownusa.org] Sent: Wednesday, June 11, 2003 11:19 AM To: Info-VAX@Mvb.Saic.Com Subject: Re: uptime-alike Howard S Shubs wrote: > > I need a program functionally like the UN*X "uptime" command. Seems to me that > I could write it. > > Getting the BOOTTIME and therefore the up-time of the machine is easy. The part > that has me stumped is how I'm going to figure out the rest, meaning the count > of pending COM[O] processes. The most recent internals data I've got is for > VAX/VMS 3.6, so I'm kinda at sea here. > > Suggestions? > > -- -- Don't know if this is what you want, but you asked for suggestions: /* ========================================================================== = = (C) Copyright 1993 The Trustees of Indiana University = = Permission to use, copy, modify, and distribute this program for = non-commercial use and without fee is hereby granted, provided that = this copyright and permission notice appear on all copies and = supporting documentation, the name of Indiana University not be used = in advertising or publicity pertaining to distribution of the program = without specific prior permission, and notice be given in supporting = documentation that copying and distribution is by permission of = Indiana University. = = Indiana University makes no representations about the suitability of = this software for any purpose. It is provided "as is" without express = or implied warranty. = ========================================================================== = = Program: uptime.c = = History: = = Version: 1.0 - September 1992 = Authors: Larry Hughes = Comment: Initial implementation. = = Version: 1.1 - September 1992 = Authors: Larry Hughes = Comment: Few minor additions. = = Version: 1.2 - January 2002 = Authors: Lyle W. West = Comment: Adjusted for VaxC --> DecC conversion = ========================================================================== */ #define VERSION "V1.2" #ifdef __DECC #pragma module UpTime VERSION #else #module UpTime VERSION /* should build with VaxC, not tested */ #endif /* ======================================================================== */ /* Includes */ /* ======================================================================== */ #include #include #include #include #include #include #include #include "statedef.h" /* ======================================================================== */ /* Defines */ /* ======================================================================== */ #define TRUE 1 #define FALSE 0 /* ====================================================================== */ /* Global Structure Definitions */ /* ====================================================================== */ struct item_list { unsigned short buffer_length; unsigned short item_code; int buffer_address; int ret_len_address; }; struct iosb_quadword { int io_status; int reserved; }; struct times { int value[2]; char buffer[23]; }; /* ====================================================================== */ /* Global Variables */ /* ====================================================================== */ /* ====================================================================== */ /* Prototypes */ /* ====================================================================== */ void scan_processes(); /* ====================================================================== */ /* Scan Process List */ /* ====================================================================== */ void scan_processes() { int status = SS$_NORMAL; int procs_total, procs_batch, procs_interactive, procs_detached, procs_network, procs_parent, procs_child, procs_suspended; int state_lef, state_hib, state_com, state_pfw, state_mwait, state_other; unsigned long pid = -1; struct times now, boot, diff; char days[6]; char hours[12]; char os_version[9]; char node[17]; $DESCRIPTOR(now_desc, now.buffer); $DESCRIPTOR(boot_desc, boot.buffer); $DESCRIPTOR(diff_desc, diff.buffer); struct { int type; int mode; int state; int pid; int mpid; } job; struct iosb_quadword iosb; struct item_list jpi_itemlist[] = { { sizeof(job.type), JPI$_JOBTYPE, &job.type, 0 }, { sizeof(job.mode), JPI$_MODE, &job.mode, 0 }, { sizeof(job.state), JPI$_STATE, &job.state, 0 }, { sizeof(job.pid), JPI$_PID, &job.pid, 0 }, { sizeof(job.mpid), JPI$_MASTER_PID, &job.mpid, 0 }, { 0, 0, 0, 0 }, }; struct item_list sys_itemlist[] = { { sizeof(boot.value), SYI$_BOOTTIME, boot.value, 0 }, { sizeof(node), SYI$_NODENAME, node, 0 }, { sizeof(os_version)-1, SYI$_VERSION, os_version, 0 }, { 0, 0, 0, 0 }, }; procs_total = procs_batch = procs_interactive = procs_detached = procs_network = procs_parent = procs_child = procs_suspended = 0; state_lef = state_hib = state_com = state_pfw = state_mwait = state_other = 0; #ifdef ARF memset(os_version, '\0', sizeof(os_version)); memset(now, '\0', sizeof(now)); memset(diff, '\0', sizeof(diff)); memset(boot, '\0', sizeof(boot)); memset(node, '\0', sizeof(node)); #else memset(os_version, 0, sizeof(os_version)); memset(now.value, 0, sizeof(now.value)); memset(now.buffer, 0, sizeof(now.buffer)); memset(diff.value, 0, sizeof(diff.value)); memset(diff.buffer, 0, sizeof(diff.buffer)); memset(boot.value, 0, sizeof(boot.value)); memset(boot.buffer, 0, sizeof(boot.buffer)); memset(node, 0, sizeof(node)); #endif /* Get the current time */ lib$date_time(&now_desc); lib$convert_date_string(&now_desc, now.value, 0, 0, 0, 0); /* Get the boot time and VMS version */ status = sys$getsyiw(0, 0, 0, sys_itemlist, 0, 0, 0); lib$sys_asctim(0, &boot_desc, boot.value, 0); /* Subtract current and boot time to get difference */ lib$sub_times(now.value, boot.value, diff.value); lib$sys_asctim(0, &diff_desc, diff.value, 0); sscanf(diff.buffer, "%s %s", days, hours); /* Print initial information */ #ifdef ARF printf("\nVMS:\t%s (%s)\n", os_version, node); printf("Date:\t%s\n", now.buffer); printf("Uptime:\t%s day%c, %s hours (since %s)\n", days, (days==1 ? '\0' : 's'), hours, boot.buffer); #else printf("\nVMS:\t%s (%s)\n", os_version, node); printf("Date:\t%s\n", now.buffer); printf("Uptime:\t%s day%c, %s hours, Boot: %s\n", days, (days==1 ? '\0' : 's'), hours, boot.buffer); #endif /* Scan each process */ while (status == SS$_NORMAL) { memset(&job, '\0', sizeof(job)); status = sys$getjpiw(0, &pid, 0, jpi_itemlist, &iosb, 0, 0); switch (status) { case SS$_NOMOREPROC: break; case SS$_SUSPENDED: procs_total++; procs_suspended++; status = SS$_NORMAL; break; case SS$_NORMAL: procs_total++; switch (job.mode) { case JPI$K_OTHER: procs_detached++; break; case JPI$K_NETWORK: procs_network++; break; case JPI$K_BATCH: procs_batch++; break; case JPI$K_INTERACTIVE: procs_interactive++; if ((job.type == JPI$K_LOCAL) || (job.type == JPI$K_REMOTE) || (job.type == JPI$K_DIALUP)) { if (job.pid == job.mpid) procs_parent++; else procs_child++; } break; }; switch(job.state) { case SCH$C_COM: case SCH$C_COMO: state_com++; break; case SCH$C_HIB: case SCH$C_HIBO: state_hib++; break; case SCH$C_LEF: case SCH$C_LEFO: state_lef++; break; case SCH$C_PFW: state_pfw++; break; #ifdef ARF case SCH$C_MWAIT: state_mwait++; break; #endif default: state_other++; break; }; break; default: exit(status); } } /* Changes below are cosmetic, not a conversion issue */ #ifdef ARF printf("Logins:\t%d interactive (with %d subprocesses)\n", procs_parent, procs_child); printf( "Procs:\tTotal %d, Interactive %d, Batch %d, Detach %d, Net %d, Suspended % procs_total, procs_interactive, procs_batch, procs_detached, procs_network, procs_suspended); printf( "States:\tLEF %d, HIB %d, COM %d, PFW %d, MWAIT %d, Other %d\n\n", state_lef, state_hib, state_com, state_pfw, state_mwait, state_other); #else printf("Logins:\t%d interactive with %d subprocesses\n", procs_parent, procs_child); printf("Procs:\tTotal: %d, Interactive: %d, Batch: %d, Detach: %d", procs_total, procs_interactive, procs_batch, procs_detached); printf(", Net: %d, Suspended: %d\n", procs_network, procs_suspended); printf("States:\tLEF: %d, HIB: %d, COM: %d, PFW: %d", state_lef, state_hib, state_com, state_pfw); printf(", MWAIT: %d, Other: %d\n\n", state_mwait, state_other); #endif } /* ======================================================================== */ /* Main Program */ /* ======================================================================== */ main(int argc, char *argv[]) { if (argc != 1) printf("Usage: uptime\n"); else scan_processes(); } /* end of program */ ----- /* (statedef.h) */ /* + * SCHEDULING STATES (statedef.h) * - * DEFINITIONS START AT 1 */ #define SCH$C_COLPG 1 /* COLLIDED PAGE WAIT */ #define SCH$C_RWAST 2 /* MUTEX AND MISCELLANEOUS RESOURCE WAIT*/ #define SCH$C_CEF 3 /* COMMON EVENT FLAG WAIT STATE */ #define SCH$C_PFW 4 /* PAGE FAULT WAIT */ #define SCH$C_LEF 5 /* LOCAL EVENT FLAG WAIT */ #define SCH$C_LEFO 6 /* LOCAL EVENT FLAG WAIT OUT OF BALANCE */ #define SCH$C_HIB 7 /* HIBERNATE WAIT */ #define SCH$C_HIBO 8 /* HIBERNATE WAIT OUT OF BALANCE SET */ #define SCH$C_SUSP 9 /* SUSPENDED */ #define SCH$C_SUSPO 10 /* SUSPENDED OUT OF THE BALANCE SET */ #define SCH$C_FPG 11 /* FREEPAGE WAIT */ #define SCH$C_COM 12 /* COMPUTE, IN BALANCE SET STATE */ #define SCH$C_COMO 13 /* COMPUTE, OUT OF BALANCE SET STATE */ #define SCH$C_CUR 14 /* CURRENT PROCESS STATE */ #define RSN$_ASTWAIT 1 /* RWAST - AST wait (system or special kernel AST) */ #define RSN$_MAILBOX 2 /* RWMBX - Mailbox full */ #define RSN$_NPDYNMEM 3 /* RWNPG - Nonpaged Dynamic memory */ #define RSN$_PGFILE 4 /* RWPFF - (1) Page file full */ #define RSN$_PGDYNMEM 5 /* RWPAG - Paged dynamic memory */ #define RSN$_BRKTHRU 6 /* RWBRK - (1) Breakthru (reply) */ #define RSN$_IACLOCK 7 /* RWIMG - (1) Image activation lock */ #define RSN$_JQUOTA 8 /* RWQUO - (1) Job pooled quota */ #define RSN$_LOCKID 9 /* RWLCK - (1) Lock identifier */ #define RSN$_SWPFILE 10 /* RWSWP - Swap file space */ #define RSN$_MPLEMPTY 11 /* RWMPE - Modified page list empty */ #define RSN$_MPWBUSY 12 /* RWMPB - Modified page writer busy #define RSN$_SCS 13 /* RWSCS - Distributed loack manager wait */ #define RSN$_CLUSTRAN 14 /* RWCLU - Cluster transition */ #define RSN$_CPUCAP 15 #define RSN$_CLUSRV 16 /* (1) may not be used */ #define RSN$_SNAPSHOT 17 #define RSN$_MAX 18 %%%%%%%%%%%%%%%%%%%%% Sorry for the size posted to to group. -- Lyle W. West To reply: Try ell with three dubya's and at with mninter arf net and use dot rather than arf __