LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2014, 06:21 AM   #1
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Rep: Reputation: Disabled
kernel parameters


I want to know how to use the kernel parameters in proc file.for example i want to get system date and time and display it.can i know the parameters which are available?
 
Old 06-23-2014, 07:45 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,963
Blog Entries: 12

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
You're going to have to clarify the question a bit more. For instance in the command line you can type "date" to get the time and date, or you can type "uptime" to get the time since boot. And then from within a program you can use functions from <time.h> to get you the time since the epoch, or convert that into a day/time which makes better sense than lengthy seconds:microseconds values.

If you're thinking that you'd access a file of any type, from any location on the system to obtain date and time; I recommend you don't do that, and instaed use either the shell commands or the functions from the provided library.
 
Old 06-24-2014, 01:23 AM   #3
shri8
LQ Newbie
 
Registered: Jun 2014
Posts: 22

Original Poster
Rep: Reputation: Disabled
I want to know how to display system time by creating a proc file for it.i tried this code
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/utsname.h>
#include<linux/time.h>
#include<sys/time.h>
struct tm *curr_tm;
static int version_proc_show(struct seq_file *m, void *v)
{
seq_printf(m,"%.2lu:%.2lu:%.2lu:%.6lu \r\n",
(curr_tm.tv_sec / 3600) % (24),
(curr_tm.tv_sec / 60) % (60),
curr_tm.tv_sec % 60,
curr_tm.tv_nsec / (1000));

return 0;
}

static int version_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, version_proc_show, NULL);
}

static const struct file_operations version_proc_fops = {
.open = version_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};

static int __init proc_version_init(void)
{
proc_create("version1", 0, NULL, &version_proc_fops);
return 0;
}
module_init(proc_version_init);

but i am getting the error /home/shaleny.s/time.c: In function ‘version_proc_show’:
/home/shaleny.s/time.c:13: error: request for member ‘tv_sec’ in something not a structure or union
what should i do?
Can i use the commands inside the proc file for getting time?
 
Old 06-24-2014, 05:11 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,882

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
curr_tm is not a struct therefore it has no members. struct tm has no member tv_sec but tm_sec. curr_tm is a pointer, you need to use:
curr_tm->tm_sec, curr_tm->tm_min ...
 
  


Reply

Tags
linux


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where to put kernel parameters farmerdave Linux - Newbie 5 08-28-2009 10:48 PM
how do you write parameters for the kernel?? rixtr66 Slackware 2 09-02-2008 08:08 PM
kernel parameters salmanucit Linux - Software 4 08-27-2008 02:19 AM
Changing Kernel Parameters aslamg Linux - Newbie 13 01-20-2006 03:57 AM
Configuring Kernel Parameters jcruzs Fedora 5 12-04-2004 02:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration