summaryrefslogtreecommitdiff
path: root/ps
diff options
context:
space:
mode:
authorStephen Brennan <stephen.s.brennan@oracle.com>2020-11-19 16:03:58 -0800
committerCraig Small <csmall@dropbear.xyz>2020-12-22 11:09:44 +1100
commit518547742beea79d3d52611ffa22c5a8df79b284 (patch)
tree3140b40c1e1a187a0d845a7e2c5225fdfc165eda /ps
parent96f8f3532c77908c1d27f2fb9b978df29f5f4f04 (diff)
downloadprocps-ng-518547742beea79d3d52611ffa22c5a8df79b284.tar.gz
Set TZ to avoid repeated stat("/etc/localtime")
With glibc, each time the strftime() function is used (twice per process in a typical ps -fe run), a stat("/etc/localtime") system call is used to determine the timezone. Not only does this add extra system call overhead, but when multiple ps processes are trying to access this file (or multiple glibc programs using strftime) in parallel, this can trigger significant lock contention within the OS kernel. Since ps is not intended to run for long periods of time as a daemon (during which the system timezone could be altered and PS might reasonably be expected to adapt its output), there is no benefit to repeatedly doing this stat(). To stop this behavior, explicitly set the TZ variable to its default value (:/etc/localtime) whenever it is unset. glibc will then cache the stat() result.
Diffstat (limited to 'ps')
-rw-r--r--ps/display.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/ps/display.c b/ps/display.c
index bec2323..1fddbbe 100644
--- a/ps/display.c
+++ b/ps/display.c
@@ -614,6 +614,7 @@ int main(int argc, char *argv[]){
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ setenv("TZ", ":/etc/localtime", 0);
#ifdef DEBUG
init_stack_trace(argv[0]);