915 |
* @param pidfile A process pidfile |
* @param pidfile A process pidfile |
916 |
* @return an uptime string |
* @return an uptime string |
917 |
*/ |
*/ |
918 |
char *get_process_uptime(char *pidfile) { |
char *get_process_uptime(char *pidfile, char *sep) { |
919 |
|
|
920 |
time_t ctime; |
time_t ctime; |
921 |
|
|
926 |
time_t now= time(&now); |
time_t now= time(&now); |
927 |
time_t since= now-ctime; |
time_t since= now-ctime; |
928 |
|
|
929 |
return get_uptime(since); |
return get_uptime(since,sep); |
930 |
|
|
931 |
} |
} |
932 |
|
|
941 |
* @param delta seconds. |
* @param delta seconds. |
942 |
* @return an uptime string |
* @return an uptime string |
943 |
*/ |
*/ |
944 |
char *get_uptime(time_t delta) { |
char *get_uptime(time_t delta, char *sep) { |
945 |
|
|
946 |
static int min= 60; |
static int min= 60; |
947 |
static int hour= 3600; |
static int hour= 3600; |
955 |
*buf= 0; |
*buf= 0; |
956 |
|
|
957 |
if((rest_d= delta/day)>0) { |
if((rest_d= delta/day)>0) { |
958 |
p+= snprintf(p, STRLEN-(p-buf), "%ldd ", rest_d); |
p+= snprintf(p, STRLEN-(p-buf), "%ldd%s", rest_d,sep); |
959 |
delta-= rest_d*day; |
delta-= rest_d*day; |
960 |
} |
} |
961 |
if((rest_h= delta/hour)>0 || (rest_d > 0)) { |
if((rest_h= delta/hour)>0 || (rest_d > 0)) { |
962 |
p+= snprintf(p, STRLEN-(p-buf),"%ldh ", rest_h); |
p+= snprintf(p, STRLEN-(p-buf),"%ldh%s", rest_h,sep); |
963 |
delta-= rest_h*hour; |
delta-= rest_h*hour; |
964 |
} |
} |
965 |
|
|
966 |
rest_m= delta/min; |
rest_m= delta/min; |
967 |
p+= snprintf(p, STRLEN-(p-buf),"%ldm ", rest_m); |
p+= snprintf(p, STRLEN-(p-buf),"%ldm%s", rest_m,sep); |
968 |
delta-= rest_m*min; |
delta-= rest_m*min; |
969 |
|
|
970 |
return xstrdup(buf); |
return xstrdup(buf); |