Path: csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: L A Walsh Newsgroups: gnu.bash.bug Subject: Re: [FR] save command times and exit status in history automatically Date: Sun, 10 Nov 2019 03:38:59 -0800 Lines: 83 Approved: bug-bash@gnu.org Message-ID: References: <8e19b0fc-4183-90fa-b067-9da636998d6f@case.edu> <5DC7F6D3.9090301@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1573385949 3599 209.51.188.17 (10 Nov 2019 11:39:09 GMT) X-Complaints-To: action@cs.stanford.edu Cc: Chester Ramey , "bash.bug list" To: Daniel Colascione Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <5DC7F6D3.9090301@tlinx.org> X-Mailman-Original-References: <8e19b0fc-4183-90fa-b067-9da636998d6f@case.edu> Xref: csiph.com gnu.bash.bug:15590 On 2019/11/07 12:18, Daniel Colascione wrote: >>> statuses? This information is practically free to collect. >>> >> Because by the time you gather this information, the command has already >> been saved completely. >> >> There have been various proposals to extend the timestamp with additional >> information, but it's all data you can gather when the timestamp is saved >> before the command is executed. >> > Why not also, optionally, save command execution times and exit ---- This sounds like you want accounting info (?). Example: I executed a perl command (using 'tperl') that exited with a status of 12. The output I got (some spaces trimmed) was: perl |v3| 1.00| 0.00| 1.00| 5013| 201| 11536.00| 0.00| 98283| 98014|12|pts/2 |Sun Nov 10 03:20:17 2019 That could be merged with history output (my HIST format is HISTTIMEFORMAT='%m%d@%H%M%S: ') 55325 1110@032011: tperl exit 12;' 55326 1110@032020: dump-acct -r /var/account/pacct |more 55327 1110@032419: man 5 acct 55328 1110@033045: history |tail -------------------- Documented in manpage 'acct(5)': Fields: #define ACCT_COMM 16 typedef u_int16_t comp_t; struct acct { char ac_flag; /* Accounting flags */ u_int16_t ac_uid; /* Accounting user ID */ u_int16_t ac_gid; /* Accounting group ID */ u_int16_t ac_tty; /* Controlling terminal */ u_int32_t ac_btime; /* Process creation time (seconds since the Epoch) */ comp_t ac_utime; /* User CPU time */ comp_t ac_stime; /* System CPU time */ comp_t ac_etime; /* Elapsed time */ comp_t ac_mem; /* Average memory usage (kB) */ comp_t ac_io; /* Characters transferred (unused) */ comp_t ac_rw; /* Blocks read or written (unused) */ comp_t ac_minflt; /* Minor page faults */ comp_t ac_majflt; /* Major page faults */ comp_t ac_swaps; /* Number of swaps (unused) */ u_int32_t ac_exitcode; /* Process termination status (see wait(2)) */ char ac_comm[ACCT_COMM+1]; /* Command name (basename of last executed command; null-terminated) */ char ac_pad[X]; /* padding bytes */ }; enum { /* Bits that may be set in ac_flag field */ AFORK = 0x01, /* Has executed fork, but no exec */ ASU = 0x02, /* Used superuser privileges */ ACORE = 0x08, /* Dumped core */ AXSIG = 0x10 /* Killed by a signal */ }; The comp_t data type is a floating-point value consisting of a 3-bit, base-8 exponent, and a 13-bit mantissa. A value, c, of this type can be converted to a (long) integer as follows: v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3); The ac_utime, ac_stime, and ac_etime fields measure time in "clock ticks"; divide these values by sysconf(_SC_CLK_TCK) to convert them to seconds.