About the two pieces of code that have been stuck to die, hope to LDD3 interested person poke open this blog:)

Source: Internet
Author: User



Want to have a little hate yourself, a few months ago encountered the "problem." There is still no solution. has been stuck to death, and can not find the reason.

Spit a groove, those only sticker code not attached to the results of the toturial, I said ... I don't understand, since some bloger codes are given.

What if I had this slag to look at the swelling? What happens when you run the results?


Description: Amount ... This problem "paste" did not attach the results of the operation, is because the direct will be stuck to my Linux host, and then I have no way to screen for everyone to see, there is no way to debug. wish to understand

------------------------------------------------


Problem code One:

/***********************************************************code Writer:eofcode Date:2014.09.02code file:proc_ Time_delay.ce-mail: [Email protected]code purpose:this code is programmed for what to delay 1 second by jiffies and HZ . If there is something wrong with my code, please touchme by e-mail. Thank you.************************************************************/#include <linux/init.h> #include < linux/module.h> #include <linux/moduleparam.h> #include <linux/fs.h> #include <linux/proc_fs.h> /* for PROCFS */#include <linux/seq_file.h>/* for ' struct seq_file ' */#include <linux/types.h> #include < linux/jiffies.h>/* for Jiffies */#define PROC_NAME "Delay_one_second" Module_author ("Jason leaster"); Module_license ("Dual BSD/GPL"); static int proc_demo_seq_show (struct seq_file* sfile,void* v) {int tmp = 0;unsigned long ji f = jiffies;unsigned Long One_second_later = jiffies + hz;for (tmp = 0; tmp < 10;tmp++) {while (Time_after (one_second_late R,jif) {jif = jiffies;} One_second_later = Jif + hz;seq_printf (sfile, "Hello world! jiffies:%lu\n", Jif);} return 0;} Static void* Proc_demo_seq_start (struct seq_file* sfile,loff_t *pos) {return NULL;} static void Proc_demo_seq_stop (struct seq_file* sfile,void* v) {/* Nothing to is done. */}static void* Proc_demo_seq_next (s Truct seq_file* sfile,void* v,loff_t* pos) {return NULL;} static struct Seq_operations Proc_demo_ops = {. start=proc_demo_seq_start,.next=proc_demo_seq_next,.stop=proc_demo_ seq_stop,.show=proc_demo_seq_show,};static int Proc_demo_open (struct inode* inode, struct file* filp) {return single_ Open (Filp,&proc_demo_seq_show,null);} struct File_operations proc_demo_fops = {. owner=this_module,.open=proc_demo_open,.read=seq_read,.release=seq_ Release,};int proc_demo_init (void) {struct Proc_dir_entry * entry = Null;entry =proc_create (proc_name,0,null,&proc _demo_fops), if (!entry) {PRINTK (kern_alert "line:%d proc_create failed!", __line__);} return 0;} void Proc_demo_exit (void) {/*** the SECond parameter of ' remove_proc_entry () ' is * * A pointer which point to parent directory. We create our** proc-entry-point in/proc/, so we pass NULL into It.*/remove_proc_entry (proc_name,null);} Module_init (Proc_demo_init); Module_exit (Proc_demo_exit);



Issue Code 2:

/***********************************************************code Writer:eofcode Date:2014.09.02code file:proc_ Time_delay.ce-mail: [Email protected]code purpose:this code is programmed for what to delay by Kerneltimer. If there is something wrong with my code, please touchme by e-mail. Thank you.************************************************************/#include <linux/init.h> #include < linux/module.h> #include <linux/moduleparam.h> #include <linux/fs.h> #include <linux/proc_fs.h> /* for PROCFS */#include <linux/seq_file.h>/* for ' struct seq_file ' */#include <linux/types.h> #include < linux/jiffies.h>/* for Jiffies */#include <linux/timer.h>/* for timer*/#include <linux/sched.h># Include <linux/slab.h> #define PROC_NAME "Delay_kernel_timer" Module_author ("Jason leaster"); Module_license ("Dual BSD/GPL"); #define LOOP 5/***first of all, you should make abstract a model** for our device driver an D include the timer.*/struct timeR_delay_model{struct timer_list timer;wait_queue_head_t wait;unsigned long prevjiffies;struct seq_file* output;int loops;/*...*/};void jif_timer_fn (unsigned long arg) {struct timer_delay_model* P_model = (struct timer_delay_model*) arg ; unsigned long jif = jiffies;seq_printf (P_model->output, "Hello world! jiffies:%lu\n", Jif);p RINTK (Kern_alert "in Jif _timer_fc%d\n ", p_model->loops);/*if (-(P_model->loops)) {p_model->timer.expires + = HZ;p_model-> prevjiffies= Jif;add_timer (&p_model->timer);} Else{wake_up_interruptible (&p_model->wait);} */p_model->loops = 0;} static int proc_demo_seq_show (struct seq_file* sfile,void* v) {unsigned long jif = jiffies;struct timer_delay_model* p_mod El;p_model = kmalloc (sizeof (struct Timer_delay_model), Gfp_kernel), if (!p_model) {PRINTK (kern_alert "Kmalloc" error in%d %s\n ", __line__,__function__); return-enomem;} ELSE{PRINTK (Kern_alert "start to Initialization%lu\n", jiffies); Init_timer (&p_model->timer); init_waitqueue_ Head (&p_model->wait);p _model->prevjiffies= jif;p_model->output= sfile;p_model->loops= LOOP;p_model-> Timer.data= (unsigned long) sfile;p_model->timer.function = jif_timer_fn;p_model->timer.expires= Jif + HZ;// Delay 1 SECONDPRINTK (kern_alert "add_timer ing%lu\n", jiffies); Add_timer (&p_model->timer);} PRINTK (Kern_alert "Add_timer finished%lu\n", jiffies);//wait_event_interruptible (p_model->wait,! ( P_model->loops)); while (Time_after (p_model->prevjiffies + hz,jif)) {jif = jiffies;} PRINTK (kern_alert "Wait finished\n"); Kfree (P_model); if (signal_pending (current)) Return-erestartsys;return 0;} Static void* Proc_demo_seq_start (struct seq_file* sfile,loff_t *pos) {return NULL;} static void Proc_demo_seq_stop (struct seq_file* sfile,void* v) {/* Nothing to is done. */}static void* Proc_demo_seq_next (s Truct seq_file* sfile,void* v,loff_t* pos) {return NULL;} static struct Seq_operations Proc_demo_ops = {. start=proc_demo_seq_start,.next=proc_demo_seq_next,.stop=proc_demo_ Seq_stop,.show=proc_demo_seq_show,};static int Proc_demo_open (struct inode* inode, struct file* filp) {return Single_open (FILP, &proc_demo_seq_show,null);} struct File_operations proc_demo_fops = {. Owner=this_module,.open=proc_demo_open,.read=seq_read,.release=single_ Release,};int proc_demo_init (void) {struct Proc_dir_entry * entry = Null;entry =proc_create (proc_name,0,null,&proc _demo_fops), if (!entry) {PRINTK (kern_alert "line:%d proc_create failed!", __line__);} return 0;} void Proc_demo_exit (void) {/*** The second parameter of ' remove_proc_entry () ' is * * A pointer which point to parent D Irectory. We create our** proc-entry-point in/proc/, so we pass NULL into It.*/remove_proc_entry (proc_name,null);} Module_init (Proc_demo_init); Module_exit (Proc_demo_exit);


Readers who have read LDD3 or ELDD can share the discussion:)











About the two pieces of code that have been stuck to die, hope to LDD3 interested person poke open this blog:)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.