linux_newb
asked on
System time
How can i retrieve the system time that is elapsed since Linux was started?
Thanks!!
Thanks!!
uptime
ASKER
uptime is a shell command . I want to use this value in my prog. Isn't there any function which can be used to assign this value to a variable inside my program?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var=`uptime`
where var is ur program variable.
sanjeev
where var is ur program variable.
sanjeev
ASKER
> you can invoke it using popen() and read in the string into a char array
i hope the format of info by uptime remains same for all versions of redHat... else it would be difficult to extract the reqd part from the string.
i hope the format of info by uptime remains same for all versions of redHat... else it would be difficult to extract the reqd part from the string.
>i hope the format of info by uptime remains same for all versions of redHat
for redhat it should be the same (cant say definitely about <6) ... any case I feel that scn's method is far superior in terms of portability and ease
from the times man page
The function times returns the number of clock ticks that have elapsed since an arbitrary point in the past. For Linux this point is the moment the system was booted. This return value may overflow the possible range of type clock_t. On error, (clock_t) -1 is returned, and errno is set appropriately.
for redhat it should be the same (cant say definitely about <6) ... any case I feel that scn's method is far superior in terms of portability and ease
from the times man page
The function times returns the number of clock ticks that have elapsed since an arbitrary point in the past. For Linux this point is the moment the system was booted. This return value may overflow the possible range of type clock_t. On error, (clock_t) -1 is returned, and errno is set appropriately.
ASKER
i meant i am relying on the fact that elapsed time immediately follows word 'up'
>i meant i am relying on the fact that elapsed time immediately follows word 'up'
should work .... if you are concerned then it can also be obtained from the proc filesystem ...
cat /proc/uptime
should work .... if you are concerned then it can also be obtained from the proc filesystem ...
cat /proc/uptime