LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-27-2010, 11:12 PM   #1
byteinnovator
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Rep: Reputation: 0
How to use write system call within a system call


I'm writing a new system call named icsys, i want to write something to the console when this system call is invoked.
i tried calling write() from icsys() but during compilation of kernel i received multiple definition error for several functions in read_write.c.
how to print
to a console from a system call.
please someone help me with this

i'm using kernel 2.6.34.1
 
Old 07-28-2010, 02:42 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
printk() ?
 
1 members found this post helpful.
Old 07-29-2010, 07:23 AM   #3
byteinnovator
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
How to use write system call within a system call

Thanks for the reply.... could you please tell me how to use printk() to print on the console.

when i use printk(), it prints in log files but i need my output on terminal.

could you please tell how to do it
 
Old 07-29-2010, 07:26 AM   #4
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
While using printk() does dmesg command say anything interesting ?

Last edited by Aquarius_Girl; 07-29-2010 at 07:30 AM.
 
Old 07-30-2010, 02:05 AM   #5
ashok449
Member
 
Registered: Sep 2007
Location: noida
Distribution: suse
Posts: 63

Rep: Reputation: 16
try below code in your system call implementation (kernel)

Code:
static void print_string(char *str)
{
 
struct tty_struct *my_tty;
        my_tty = current->signal->tty;

        if (my_tty != NULL) {


                ((my_tty->driver)->ops->write) (my_tty,str,strlen(str));

                ((my_tty->driver)->ops->write) (my_tty, "\015\012", 2);

        }
}

-- Ashok
 
1 members found this post helpful.
Old 07-30-2010, 02:12 AM   #6
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
<Irrelevant content deleted>

Last edited by Aquarius_Girl; 07-30-2010 at 02:34 AM.
 
Old 07-30-2010, 02:33 AM   #7
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by anishakaul View Post
To whom are you telling this ? Who is going to try this ?

I just asked you in post number 4 to execute dmesg command and see what printk () writes there !
Ashok

I am extremely sorry for the post number 6 of mine ! I thought you are the OP

Last edited by Aquarius_Girl; 07-30-2010 at 02:40 AM.
 
Old 07-30-2010, 02:37 AM   #8
ashok449
Member
 
Registered: Sep 2007
Location: noida
Distribution: suse
Posts: 63

Rep: Reputation: 16
He is trying to implement a system call and I thought he is well aware of printk().

I just tried to help him, Anyhow I already posted it, may be someone else will use this post later. we should not use this site for such comments. We are here to help.

--Ashok
 
1 members found this post helpful.
Old 07-30-2010, 02:39 AM   #9
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Read my post number 7: I thought you were the creator of this thread
 
Old 07-30-2010, 07:43 AM   #10
byteinnovator
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks guys, i will try what u said and let u know about the progress
 
Old 07-30-2010, 07:45 AM   #11
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by byteinnovator View Post
Thanks guys, i will try what u said and let u know about the progress
Try the dmesg command, it will not take much time, I think by that you will be able to see printk's output on the console !
 
Old 07-31-2010, 08:11 AM   #12
byteinnovator
LQ Newbie
 
Registered: Jul 2010
Posts: 5

Original Poster
Rep: Reputation: 0
HI anishakaul,

This is wat i actually want to do, when i call a system call i need to some messages directly displayed on terminal, i dont want to use dmesg.

Its something like redirection to terminal. can u tell how to do it,
 
Old 07-31-2010, 09:25 AM   #13
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Does the following code solves your problem ? Try it !
Code:
printk(KERN_CRIT "I am a critical level printk");
Search the man page for printk on the net,

Last edited by Aquarius_Girl; 07-31-2010 at 09:31 AM.
 
Old 08-03-2010, 09:31 PM   #14
archieval
Member
 
Registered: Apr 2007
Location: Philippines
Distribution: Kubuntu, Ubuntu, CentOS
Posts: 289

Rep: Reputation: 41
write() is user space, why use it in kernel space?
 
Old 08-04-2010, 12:37 AM   #15
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by archieval View Post
write() is user space, why use it in kernel space?
write() is used for low-level I/O. What else in your view point should be used for writing in Kernel modules ? Kindly enlighten.
 
  


Reply



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
modifying write system call linuxdoniv Programming 14 08-08-2008 06:10 AM
How can i make centos 4.5's system call using vDSO(call *%gs:0x10) instead of int80 tclwp Red Hat 3 08-06-2007 12:07 AM
how to write my own system call in mandrake 10.2 jawahar_bits Linux - Kernel 2 02-03-2007 10:14 AM
write system call basics.... bisDude Programming 6 11-04-2005 06:48 PM
How to write a system call to display the process information? balasquare@yahoo.com Programming 3 09-30-2005 01:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 02:58 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
Open Source Consulting | Domain Registration