LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   kernel parameters (https://www.linuxquestions.org/questions/linux-newbie-8/kernel-parameters-4175508869/)

shri8 06-23-2014 05:21 AM

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?

rtmistler 06-23-2014 06:45 AM

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.

shri8 06-24-2014 12:23 AM

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?

pan64 06-24-2014 04:11 AM

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 ...


All times are GMT -5. The time now is 04:52 PM.