LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Time oriented program in kernel space (https://www.linuxquestions.org/questions/linux-newbie-8/time-oriented-program-in-kernel-space-785338/)

Gourab Das 01-28-2010 07:13 AM

Time oriented program in kernel space
 
Hi all,
I have written a programme in gcc
#include <time.h>
#include <stdio.h>
int main(void)
{
time_t timer;
struct tm *tblock;
timer = time(NULL);
tblock = localtime(&timer);
printf("%d",tblock->tm_mday);
return 0;
}

It has been compiled in gcc.But in kernel space it hasn't been solved. Please can anyone suggest the kernel space version of this code.

jschiwal 01-29-2010 12:02 AM

In userland you run library functions that call system functions or call those functions directly. The kernel carries out these actions for you.

In kernel programming, you are on the other side of the fence. You aren't using the same C runtime library and the same standard libraries. Functions like printf do not exist. There are books on Linux Kernel development. You will also need to resort to reading kernel source code, as the code changes rapidly.

For low-resolution time that also works if no high-resolution clocks are available look at "getnstimeofday".

sundialsvcs 01-29-2010 11:25 AM

The kernel is a very specialized programming environment, specifically designed for "hardware control" and for creating the rich environment in which ordinary programs can run. Anything that does not clearly fall within that narrow interpretation doesn't belong in the kernel.

There are many essential programs, such as the venerable init, which run in "user-land" with rootly privileges. The system cannot and will not run without these programs, yet they run in the user environment.


All times are GMT -5. The time now is 12:09 AM.