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 01-28-2010, 08:13 AM   #1
Gourab Das
LQ Newbie
 
Registered: Jan 2010
Posts: 10

Rep: Reputation: 0
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.
 
Old 01-29-2010, 01:02 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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".

Last edited by jschiwal; 01-29-2010 at 01:04 AM.
 
Old 01-29-2010, 12:25 PM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 7,183

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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.
 
  


Reply


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
time function in kernel space Gourab Das Linux - Newbie 1 01-26-2010 03:27 PM
Segmentation fault in libpacp oriented program Neminath Programming 2 05-05-2009 11:06 PM
how to measure execution time in kernel space? didio Linux - Kernel 1 10-08-2007 11:01 PM
How to write a object oriented c program? ssg14j Programming 2 08-17-2005 11:47 AM
How to write a object oriented program using c ssg14j Programming 6 08-10-2005 10:56 AM


All times are GMT -5. The time now is 09:41 PM.

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