Answering old thread for new interested stumblers.
We re going to make a lightweight C program called getProcStartTime
that you ll have plenty of other uses for. It tells you when a process was started, given the PID. I believe you will still get a time stamp down to the second even if the process was started months or years ago. Save this source code as a file called getProcStartTime.c:
#include <time.h>
#include <procinfo.h>
main(argc, argv)
char *argv[];
{
struct procentry64 psinfo;
pid_t pid;
if (argc > 1) {
pid = atoi(argv[1]);
}
else {
printf("Usage : getProcStartTime pid
");
return 1;
}
if (getprocs64(&psinfo, sizeof(struct procentry64), NULL, sizeof(struct fdsinfo64) , &pid, 1) > 0) {
time_t result;
result = psinfo.pi_start;
struct tm* brokentime = localtime(&result);
printf("%s", asctime(brokentime));
return 0;
} else {
perror("getproc64");
return 1;
}
}
Then compile it:
gcc getProcStartTime.c -o getProcStartTime
Here s the magic logic: AIX just like Linux has a process called init
with PID 1. It can t be killed or restarted. So the start time of PID 1 is the boot time of your server.
./getProcStartTime 1
On my server, returns Wed Apr 23 10:33:30 2014; yours will be different.
Note, I originally made getProcStartTime
specifically for this purpose, but now I use it in all kinds of other scripts. Want to know how long an Oracle database has been up? Find the PID of Oracle s PMON and pass that PID as your arg after getProcStartTime
.
If you really want the output as an integer number of seconds, it would be an easy programming exercise to modify the code above. The name getProcUptime
is just a suggestion. Then you could just call:
./getProcUptime 1
UPDATE: Source code and precompiled binary for AIX 6.1/7.1 have been put on my Github repo here: https://github.com/Josholith/getProcStartTime