Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System time

Posted on 2003-11-20
9
Medium Priority
?
263 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 60 total points
ID: 9794655
you can invoke it using popen() and read in the string into a char array
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 3

Accepted Solution

by:
scn earned 60 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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 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 video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

688 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