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 6882835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:18:17+00:00 2026-05-27T05:18:17+00:00

I need to write some kernel module for my university classes and now I’m

  • 0

I need to write some kernel module for my university classes and now I’m trying to understand various kernel mechanisms that I have to use. One of them are wait queues. I wrote a simple module that registers a /proc entry and does some simple logic inside its read function:

DECLARE_WAIT_QUEUE_HEAD(event);

volatile int condvar = 0;
volatile int should_wait = 1;

int simple_read_proc(char *page, char **start, off_t offset, int count, int *eof, void *data) {
    printk(KERN_INFO "simple_read_proc from %i\n", current->pid);
    if(should_wait == 1) {
        printk(KERN_INFO "Waiting in %i\n", current->pid);
        should_wait = 0;
        wait_event_interruptible(event, condvar == 1);
        printk(KERN_INFO "Wait finished in %i\n", current->pid);
        condvar = 0;
        return sprintf(page, "%s", "The wait has finished!\n");
    } else {
        printk(KERN_INFO "Waking up in %i\n", current->pid);
        condvar = 1;
        wake_up_interruptible(&event);
        return sprintf(page, "%s", "Woke up the other process!\n");
    }
}

This is what happens when I try to run cat twice on the registered /proc file:

First cat process waits for the second one to wake him up. Second cat process does exactly that. Each process prints what it should. So far, everything as planned. But then I look into dmesg and that is what I see:

[11405.484168] Initializing proc_module
[11413.209535] simple_read_proc from 6497
[11413.209543] Waiting in 6497
[11415.498482] simple_read_proc from 6499
[11415.498489] Waking up in 6499
[11415.498507] simple_read_proc from 6499
[11415.498514] Wait finished in 6497
[11415.498518] Waking up in 6499
[11415.498546] simple_read_proc from 6497
[11415.498550] Waking up in 6497
[11415.498554] simple_read_proc from 6497
[11415.498557] Waking up in 6497
[11415.498689] simple_read_proc from 6499
[11415.498694] Waking up in 6499
[11415.498753] simple_read_proc from 6497
[11415.498757] Waking up in 6497

My question is: why the simple_read_proc function was invoked so many times? I thought that this may be because cat invoked read many times, but I checked it with strace and this is not the case – each cat invoked read only once.

I would be grateful for some explanation of this phenomenon.

  • 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-05-27T05:18:18+00:00Added an answer on May 27, 2026 at 5:18 am

    Look at the comment in fs/proc/generic.c about “How to be a proc read function.” Since you are not changing eof, the loop in __proc_file_read will call your read_proc function multiple times.

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

Sidebar

Related Questions

I need to write a kernel module that is not a device driver. That
I need to write some methods for loading/saving some classes to and from a
I need to write some sql that will allow me to query all objects
I need to write some code that would loop though all rows of a
I need to write some data in several database. I choose sqlapi.com I have
Hallo, i need to write some javascript that gets the contents of a userfield
I need to write some code that uses TcpListener . The object that using
I need to write some junit tests on Java code that calls Math.random() .
I am trying to write a module with some c and some python parts.
I need to write some code in PHP that performs an action only on

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.