Solved

System time

Posted on 2003-11-20
9
260 Views
Last Modified: 2010-04-22
How can i retrieve the system time that is elapsed since Linux was started?

Thanks!!
0
Comment
Question by:linux_newb
9 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9794242
uptime
0
 

Author Comment

by:linux_newb
ID: 9794626
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?
0
 
LVL 45

Assisted Solution

by:sunnycoder
sunnycoder earned 20 total points
ID: 9794655
you can invoke it using popen() and read in the string into a char array
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Accepted Solution

by:
scn earned 20 total points
ID: 9795523
man 2 times
times( ) returns the number of jiffies elapsed since system was started.
Seconds = jiffies / HZ  (HZ is defined in include "asm/param.h")
0
 

Expert Comment

by:S_KuMaaaaR
ID: 9817212
var=`uptime`

where var is ur program variable.

sanjeev
0
 

Author Comment

by:linux_newb
ID: 9830512
> 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.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9830559
>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.

0
 

Author Comment

by:linux_newb
ID: 9830564
i meant i am relying on the fact that elapsed time immediately follows word 'up'
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9830569
>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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Avoiding pop-up when starting a linux scrip/shell 5 109
Embeded Linux on Router 9 109
Cron jobs 12 136
shell script or linux command to upload a directory to artifactory? 2 204
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question