Solved

System time

Posted on 2003-11-20
9
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

632 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