Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:08:59+00:00 2026-06-05T23:08:59+00:00

I wrote a simple code to capture the netdevice notifications and simply print their

  • 0

I wrote a simple code to capture the netdevice notifications and simply print their value out to the messages log file … here’s the code :

#include <linux/notifier.h>
#include <asm/kdebug.h> 
#include <linux/netdevice.h>
#include <linux/inetdevice.h>

int my_dev_event_handler (struct notifier_block *self,unsigned long val, void *data)
{
    printk (KERN_INFO "my_dev_event: Val=%ld, Interface=%s\n", val,((struct net_device *) data)->name);
    return 0;
}

static struct notifier_block my_dev_notifier = {
.notifier_call = my_dev_event_handler,
};

static int __init
my_init (void)
{
printk(KERN_ALERT "***Module Loaded***\n");
register_netdevice_notifier (&my_dev_notifier); 

   return 0;
}

static void __exit my_end(void)
{
    printk(KERN_ALERT "***Module Unloaded***\n");
}

module_init(my_init);
module_exit(my_end);

this code compiles and runs correctly, it prints out the “my_dev_event:…” line every time a device goes up/off … but sometimes (not always) the entire system freezes when a device goes up\down … now I have two questions here:
1- why is the system freezing? anything wrong with this code?
2- if there’s a better way to notify my kernel module when a device goes connected/disconnected …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:09:01+00:00Added an answer on June 5, 2026 at 11:09 pm

    The only problem I see is that my_end doesn’t unregister the notifier.
    This can cause crashes or freezes after you’ve unloaded your module. This is because a pointer to your code remains in Linux data structures, but your code is no longer there.

    Regarding an alternative way – I think you’re using the correct way to get these notifications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello every one I have wrote a simple code in html5 in which I
I wrote this simple C code and compiled it using Visual Studio 2010, with
I've wrote this simple piece of code. And I have a slight problem with
I wrote a simple example that I expected would do it. The relevant code
I want to write a simple web proxy, for exercise. Here's the code I
here is a sample code. If I remove the stdafx.h file, the program wont
I wrote some simple code : var tm='<input type=checkbox name=city[] />'; tm=$(tm).val('2'); alert($(tm).text()); //
i wrote the simple code ContentResolver contentResolver = this.getContentResolver(); Uri uriSMSURI = Uri.parse(content://sms/); //
I've wrote simple RMI code to learn how it works. While everything works fine
For get device id in android sdk i wrote simple This code :: import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.