for (i = 0; i < npids; i++) {
pid = pids[i];
- snprintf(path, sizeof(path), _PATH_PROC "/%u/psinfo", pid);
+ snprintf(path, sizeof(path), _PATH_PROC "%u/psinfo", pid);
/* Processes may legitimately disappear between calls. */
if ((fp = fopen(path, "r")) == NULL)
int fd, argc;
/* Get the command line of the process from procfs. */
- snprintf(path, sizeof(path), _PATH_PROC "/%u/cmdline", p->p_pid);
+ snprintf(path, sizeof(path), _PATH_PROC "%u/cmdline", p->p_pid);
if ((fd = open(path, O_RDONLY)) < 0)
return NULL;
*/
return p1->p_pid < p2->p_pid;
}
+
+/*
+ * Obtain the system uptime in seconds. Return 0 on success, with the uptime
+ * stored in the given time_t field. Return -1 on failure.
+ */
+int
+minix_getuptime(time_t *timep)
+{
+ FILE *fp;
+ int r;
+
+ if ((fp = fopen(_PATH_PROC "uptime", "r")) == NULL)
+ return -1;
+
+ r = fscanf(fp, "%llu", timep);
+
+ fclose(fp);
+
+ return (r == 1) ? 0 : -1;
+}
double avenrun[3];
time_t uptime;
int days, hrs, mins;
+#ifndef __minix
int mib[2];
size_t size, i;
+#else
+ size_t i;
+#endif /* __minix */
char buf[256];
/*
* Print how long system has been up.
* (Found by looking getting "boottime" from the kernel)
*/
+#ifndef __minix
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
boottime.tv_sec != 0) {
uptime = now - boottime.tv_sec;
+#else
+ if (minix_getuptime(&uptime) != -1) {
+#endif /* __minix */
uptime += 30;
if (uptime > SECSPERMIN) {
days = uptime / SECSPERDAY;