Re: Re: Re: Re: query related to /proc and read_write.c file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Let me tell you whatever I have understood about this (I am very much a newbie and hope my mistakes will be excused if there are any :-)

The entries in /proc are really more of an interface than really physical files. This might be apparent from the fact that the size reported by 'ls' for an entry in /proc (say ksyms) is zero even though when I do "cat /proc/ksyms", I get a whole lot of data. So the information returned is generated dynamically rather being present in a file in /proc for a period of time.

Whenever you do a read/write operation on an entry in /proc, data is being exchanged between the user-process and kernel by means of the defined read and write functions for that entry. That means when you do a "cat /proc/<entry>", what you see is not really the contents of a physical file /proc/<entry>, rather it is some data stored or generated by the kernel and copied to the user-process through the read function defined for it.

So assuming that your intent is to have a different text string returned when you invoke "cat /proc/<entry>" at two minute intervals, what you essentially do is to change the contents of the char array in kernel repeatedly at similar intervals and then return it through the read function as a response to 'cat'. (check out the 'module_output' function in chapter 6 of Linux Kernel Modules Programming Guide). If you want to do the same from a program, you can use the 'open' and 'read' on /proc/<entry> and you will get the same value as with 'cat'. 

Hope this helps,
Praveen.

On Wed, 28 Apr 2004 bunty  wrote :
>hi Praveen,
>              what i want to know that can it be possible to crate a /proc entry that can kernel read and write after few period.
>               what i want to generate a randome text based on net_random function. the file in /proc will be updated after 2 minutes.
>  Regarding create proc entry i understand it. but what i want can it be possible. it is actually part of waht i want to modify in kernel.
>regards,
>parag.
>
>
>On Tue, 27 Apr 2004 Praveen Pathiyil wrote :
> >Hi Parag,
> >
> >I am not sure whether I understand your original question correctly. However if you are looking for a way to communicate between the kernel and user space through the /proc interface, the link given below (Chapter 5 of LKPMG) does talk about it.
> >
> >However you will need to use "create_proc_entry" or "create_proc_read_entry" in kernels 2.4 or higher (according as to whether you need a read/write or a read-only interface) instead of "proc_register" as given there. You can check out the code in the file
> ><linux-src>/fs/proc/proc_misc.c
> >
> >In create_proc_read_entry, you can directly specify a read function. If you are using create_proc_entry, you will have to specify the read and write functions through appropriate entries of "struct proc_dir_entry" and "struct file_operations".
> >
> >regards,
> >Praveen.
> >
> >On Tue, 27 Apr 2004 mohanlal jangir wrote :
> > >See this
> > >http://www.dirac.org/linux/writing/lkmpg/lkmpg.html#AEN715
> > >
> > >Also read about copy_to_user/copy_from_user functions.
> > >
> > >Regards
> > >Mohanlal
> > >
> > >----- Original Message -----
> > > From: "bunty" <bunty123_4@rediffmail.com>
> > >To: <kernelnewbies@nl.linux.org>; <mohanlal@samsung.com>;
> > ><omanakuttan@tataelxsi.co.in>
> > >Sent: Monday, April 26, 2004 8:24 PM
> > >Subject: query related to /proc and read_write.c file
> > >
> > >
> > >hello,
> > >   1) how kernel write to /proc entry? while studying kernel source i found
> > >that there is no open/read/write/close file functions.
> > >what i found is that sprintf function that writes to /proc entry. can anyone
> > >please explain it?
> > >
> > >    2)what is the use of read_write.c file in fs directory of kernel source?
> > >the file contains sys_read, sys_write. why there is no function that will
> > >read a user space file and write to it.
> > >i found few questions asked on linux-kernel as well as kernelnewbies but
> > >there is no one able to answer it?
> > >i am using kernel 2.4.24.
> > >regards,
> > >parag.
> > >
> > >
> > >--
> > >Kernelnewbies: Help each other learn about the Linux kernel.
> > >Archive:       http://mail.nl.linux.org/kernelnewbies/
> > >FAQ:           http://kernelnewbies.org/faq/
> > >

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux