psacct/psacct-6.6.3-lastcomm-new-pid-option.patch

106 lines
3.3 KiB
Diff

diff -up ./lastcomm.1.ori ./lastcomm.1
--- ./lastcomm.1.ori 2017-02-08 23:28:06.000000000 +0100
+++ ./lastcomm.1 2017-06-22 16:21:46.249345984 +0200
@@ -122,13 +122,10 @@ format as your current machine, but has
.B AHZ.
.TP
.B \-p, \-\-show\-paging
-Print paging statistics
+Print paging statistics.
.TP
.B \-\-pid
-Add pid of the process and pid of the process parent to the output
-(pid is the last but one and parent pid the last column).
-These values are shown only when they are generated by acct function
-(depends on the version of kernel)
+Show PID and PPID of the process if acct version 3 format is supported by kernel.
.TP
.B \-\-debug
Print verbose internal information.
diff -up ./lastcomm.c.ori ./lastcomm.c
--- ./lastcomm.c.ori 2017-04-05 23:06:33.000000000 +0200
+++ ./lastcomm.c 2017-06-22 16:21:14.814430103 +0200
@@ -77,6 +77,8 @@ char *program_name; /* name of the prog
int show_paging = 0; /* If they want paging stats, print 'em */
+char show_pid = 0;
+
static unsigned int hzval;
/* Here are various lists for the user to specify entries that they
@@ -125,6 +127,9 @@ int main(int argc, char *argv[])
{ "show-paging", no_argument, NULL, 11 },
#endif
{ "forwards", no_argument, NULL, 12 },
+#ifdef LINUX_MULTIFORMAT
+ { "pid", no_argument, NULL, 13},
+#endif
{ 0, 0, 0, 0 }
};
@@ -209,6 +214,9 @@ int main(int argc, char *argv[])
}
backwards = 0;
break;
+ case 13:
+ show_pid = 1;
+ break;
case 'h':
case 3:
/* This should fall through to default! */
@@ -304,6 +312,7 @@ void give_usage(void)
#ifdef HAVE_PAGING
"[--show-paging] "
#endif
+ "[--pid] "
"[--ahz <freq>] [--version] [--help]\n", program_name);
print_acct_file_location ();
}
@@ -392,8 +401,8 @@ void parse_entries(void)
(void)putchar(' ');
btime = (time_t) rec->ac_btime;
- if ( show_paging == 0 )
- (void)printf(" %-8.8s %-8.8s %6.2f secs %-16.16s\n",
+ if ( show_paging == 0)
+ (void)printf(" %-8.8s %-8.8s %6.2f secs %-16.16s",
this_uid, this_dev,
#ifdef LINUX_MULTIFORMAT
((ut + st) / (double) rec->ac_ahz),
@@ -403,7 +412,7 @@ void parse_entries(void)
ctime (&btime));
else
#ifdef HAVE_PAGING
- (void)printf(" %6.0fmin %6.0fmaj %4.0fswp %6.2f secs %-16.16s\n",
+ (void)printf(" %6.0fmin %6.0fmaj %4.0fswp %6.2f secs %-16.16s",
minf, majf, swap,
#ifdef LINUX_MULTIFORMAT
((ut + st) / (double) rec->ac_ahz),
@@ -412,8 +421,24 @@ void parse_entries(void)
#endif
ctime (&btime));
#else
- (void)printf(" --- No paging statistics! --- \n" );
+ (void)printf(" --- No paging statistics! --- " );
#endif
+
+
+ if (show_pid)
+ {
+#ifdef LINUX_MULTIFORMAT
+ if ((rec->ac_version & 0x7f) == 3)
+ {
+ (void) printf(" %d %d", rec->ac_pid, rec->ac_ppid);
+ }
+#else
+ (void)printf(" --- No PID information available! --- " );
+#endif
+ }
+
+
+ (void) printf("\n");
}
}
}