Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to read graphic card info in proc module.I created a proc module and loaded it to kernel.What I want is to show graphic card info when I call the proc from terminal. Such as " cat /proc/myprocname" I know that my code is wrong below.But it will help you to understand what I want.

#include <linux/init.h>        
#include <linux/module.h>  
#include <linux/proc_fs.h>       // proc filesystem

/* 
read proc function
*/
int read_proc(char *buf, char **start, off_t offset,
int count, int *eof, void *data){

   // !! **that's it.I want to read graphic card info in this function.**
   // !! this is wrong.but I want to do like this

   FILE *fd = popen("lspci | grep VGA", "r");
char buffer[16];
if (fread (buffer, 1, sizeof (buffer), fd) > 0) // if there is some result the     module must be loaded
printk (KERN_INFO buffer);
else
printf ("module is not loaded\n");
return 1;
}
/*
Module loading...
*/

static int baslat(void){

//  Registering..

create_proc_read_entry( "proc01",  // file name
              0,           //  (protection mode): default 
              NULL,        //  (parent dir): none
              read_proc,   // callback
              NULL);       //
 return 0;
}
/*
Module removing..
*  /

static void bitir(void){
// module register removing..
remove_proc_entry( "proc01",   // file name 
             NULL);        // (parent directory)
}
module_init(baslat);
module_exit(bitir);
share|improve this question
add comment

1 Answer 1

You can cat any proc file:

➜  ~  cat /proc/dri/0/vm
slot     offset       size type flags    address mtrr

➜  ~  cat /proc/dri/0/vma
vma use count: 0, high_memory = f79fe000, 0x379fe000
➜  ~  cat /proc/dri/0/gem_names 
  name     size handles refcount
     1  3145728       1        3
     2     4096       2        3
     3  3145728       2        3
     4  3145728       1        3
     5  3145728       2        3
     6  3035136       2        3
     7  1679360       2        3
     8  3035136       2        3
     9  1998848       2        3

You didn't said what is your graphic card, but this should put you in the right track.

share|improve this answer
    
Thank you for reply but I do not mean how to learn it in terminal.I have to learn it in proc module.I have to write a proc module and load it to the kernel.After that,when I write "cat /proc/myprocname" to terminal,it will show me the graphic card info. if it were not required to get info graphic card info by using proc module,I would learn it typing to the terminal " lspci | grep VGA" or etc. I mean how to learn g. card info using read proc function in proc module.what should I write in read proc function ? –  Mustafa Dec 11 '13 at 19:47
    
@Mustafa exactly what you want? Can you edit your question and tell us 1) what are you trying to do 2) What results you expect 3) how you plan to get them 4) the problem you are finding –  Braiam Dec 11 '13 at 20:00
    
Maybe he wants to write a kernel module? –  falconer Dec 11 '13 at 20:02
    
I've got it. :) –  falconer Dec 11 '13 at 21:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.