Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jul 1995 23:02:54 +0200
From:      Wolfram Schneider <w@cs.tu-berlin.de>
To:        current@freebsd.org, wosch@cs.tu-berlin.de
Subject:   New options for lastcomm(1)
Message-ID:  <199507202102.XAA03168@localhost.cs.tu-berlin.de>

next in thread | raw e-mail | index | archive | help

Example:

$ lastcomm  -e kermit
kermit     -FX     w        ttyp2      366.50 es 


>From the manpage:

     lastcomm [-EScesu] [-f file] [command ...] [user ...] [terminal ...]


     The following options are available:

     -E		The time the process exited.

     -S		The time the process started, default.


     -c		The amount of cpu time used by the process (in seconds), de-
		 fault.

     -e		The amount of elapsed time used by the process (in seconds).

     -s		The amount of system time used by the process (in seconds).

     -u		The amount of user time used by the process (in seconds).


     Use [-cS] as default if no one of these previous options called.



--- 1.1	1995/07/20 13:09:21
+++ lastcomm.c	1995/07/20 14:49:22
@@ -29,6 +29,9 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ *     @(#)lastcomm.c	8.1 (Berkeley) 6/6/93
+ *  $Id: $
  */
 
 #ifndef lint
@@ -63,6 +66,16 @@
 void	 usage __P((void));
 char	*user_from_uid();
 
+#define AC_UTIME 1 /* user */
+#define AC_STIME 2 /* system */
+#define AC_ETIME 4 /* elapsed */
+#define AC_CTIME 8 /* user + system time, default */
+
+#define AC_BTIME 16 /* starting time */
+#define AC_FTIME 32 /* exit time (starting time + elapsed time )*/
+
+#define AC_HZ ((double)AHZ)
+
 int
 main(argc, argv)
 	int argc;
@@ -76,17 +89,46 @@
 	time_t t;
 	int ch;
 	char *acctfile;
+	int time = 0;
 
 	acctfile = _PATH_ACCT;
-	while ((ch = getopt(argc, argv, "f:")) != EOF)
+	while ((ch = getopt(argc, argv, "f:usecSE")) != EOF)
 		switch((char)ch) {
 		case 'f':
 			acctfile = optarg;
 			break;
+
+		case 'u': 
+			time |= AC_UTIME; /* user time */
+			break;
+		case 's':
+			time |= AC_STIME; /* system time */
+			break;
+		case 'e':
+			time |= AC_ETIME; /* elapsed time */
+			break;
+        	case 'c':
+                        time |= AC_CTIME; /* user + system time */
+			break;
+
+        	case 'S':
+                        time |= AC_BTIME; /* starting time */
+			break;
+        	case 'E':
+			/* exit time (starting time + elapsed time )*/
+                        time |= AC_FTIME; 
+			break;
+
 		case '?':
 		default:
 			usage();
 		}
+
+	/* default user + system time and starting time */
+	if (!time) {
+	    time = AC_CTIME | AC_BTIME;
+	}
+
 	argc -= optind;
 	argv += optind;
 
@@ -134,12 +176,47 @@
 		if (*argv && !requested(argv, &ab))
 			continue;
 
-		t = expand(ab.ac_utime) + expand(ab.ac_stime);
-		(void)printf("%-*s %-7s %-*s %-*s %6.2f secs %.16s\n",
+		(void)printf("%-*s %-7s %-*s %-*s ",
 			fldsiz(acct, ac_comm), ab.ac_comm, flagbits(ab.ac_flag),
 			UT_NAMESIZE, user_from_uid(ab.ac_uid, 0),
-			UT_LINESIZE, getdev(ab.ac_tty),
-			t / (double)AHZ, ctime(&ab.ac_btime));
+			UT_LINESIZE, getdev(ab.ac_tty));
+
+
+		/* user + system time */
+		if (time & AC_CTIME) {
+		    (void)printf("%6.2f secs ", 
+				 (expand(ab.ac_utime) + 
+				  expand(ab.ac_stime))/AC_HZ);
+		}
+
+		/* usr time */
+		if (time & AC_UTIME) {
+		    (void)printf("%6.2f us ", expand(ab.ac_utime)/AC_HZ);
+		}
+
+		/* system time */
+		if (time & AC_STIME) {
+		    (void)printf("%6.2f sy ", expand(ab.ac_stime)/AC_HZ);
+		}
+
+		/* elapsed time */
+		if (time & AC_ETIME) {
+		    (void)printf("%8.2f es ", expand(ab.ac_etime)/AC_HZ);
+		}
+
+		/* starting time */
+		if (time & AC_BTIME) {
+		    (void)printf("%.16s ", ctime(&ab.ac_btime));
+		}
+
+		/* exit time (starting time + elapsed time )*/
+		if (time & AC_FTIME) {
+		    t = ab.ac_btime;
+		    t += (time_t)(expand(ab.ac_etime)/AC_HZ);
+		    (void)printf("%.16s ", 
+				 ctime(&t));
+		}
+		printf("\n");
 	}
 	exit(0);
 }
@@ -217,6 +294,6 @@
 usage()
 {
 	(void)fprintf(stderr,
-	    "lastcomm [ -f file ] [command ...] [user ...] [tty ...]\n");
+	    "lastcomm [-EScesu] [ -f file ] [command ...] [user ...] [tty ...]\n");
 	exit(1);
 }
--- 1.1	1995/07/20 14:40:29
+++ lastcomm.1	1995/07/20 15:01:22
@@ -30,6 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)lastcomm.1	8.1 (Berkeley) 6/6/93
+.\" $Id: $
 .\"
 .Dd June 6, 1993
 .Dt LASTCOMM 1
@@ -39,6 +40,7 @@
 .Nd show last commands executed in reverse order
 .Sh SYNOPSIS
 .Nm lastcomm
+.Op Fl EScesu
 .Op Fl f Ar file
 .Op Ar command ...
 .Op Ar user ...
@@ -50,8 +52,35 @@
 .Nm lastcomm
 prints information about all the commands recorded
 during the current accounting file's lifetime.
+
 .Pp
-Option:
+The following options are available:
+.Pp
+.Bl -tag -width Fl
+.Pp
+.It Fl E
+The time the process exited.
+.Pp
+.It Fl S
+The time the process started, default.
+
+.It Fl c
+The amount of cpu time used by the process (in seconds), default.
+.It Fl e
+The amount of elapsed time used by the process (in seconds).
+.It Fl s
+The amount of system time used by the process (in seconds).
+.It Fl u
+The amount of user time used by the process (in seconds).
+.El
+
+.Pp
+Use 
+.Op Fl cS
+as default if no one of these previous options called.
+.Pp
+.Pp
+
 .Pp
 .Bl -tag -width Fl
 .It Fl f Ar file
@@ -95,7 +124,8 @@
 .It
 The amount of cpu time used by the process (in seconds).
 .It
-The time the process exited.
+.\" Wrong: The time the process exited.
+The time the process started.
 .El
 .Pp
 The flags are encoded as follows: ``S'' indicates the command was



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199507202102.XAA03168>