Solved

System time

Posted on 2003-11-20
9
257 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
Comment Utility
uptime
0
 

Author Comment

by:linux_newb
Comment Utility
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
Comment Utility
you can invoke it using popen() and read in the string into a char array
0
 
LVL 3

Accepted Solution

by:
scn earned 20 total points
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Expert Comment

by:S_KuMaaaaR
Comment Utility
var=`uptime`

where var is ur program variable.

sanjeev
0
 

Author Comment

by:linux_newb
Comment Utility
> 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
Comment Utility
>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
Comment Utility
i meant i am relying on the fact that elapsed time immediately follows word 'up'
0
 
LVL 45

Expert Comment

by:sunnycoder
Comment Utility
>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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now