Solved

System time

Posted on 2003-11-20
9
258 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bash Script to find & Kill Multiple Process 3 94
Getting permission denied on linux running a script 3 66
Help with a backup script in Linux 4 75
Linux Scripting 3 102
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

17 Experts available now in Live!

Get 1:1 Help Now