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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:52:33+00:00 2026-06-10T09:52:33+00:00

I introduce my self in the driver programming via a book. This book is

  • 0

I introduce my self in the driver programming via a book.

This book is about Linux-driver programming with a 2.6 Kernel.
But now I met a problem.
I copied the following code from the book.
And tried to understand it. So far, so good.

#include <linux/module.h>
#include <linux/version.h>
#include <linux/init.h>
#include <linux/completion.h>


static int thread_id=0;
static wait_queue_head_t wq;
static DECLARE_COMPLETION( on_exit );
static int thread_code( void *data )
{
    unsigned long timeout;
    int i;
    daemonize("MyKThread");
    allow_signal( SIGTERM );
    for( i=0; i<10; i++ ) {
        timeout=HZ; // wait 1 second
        timeout=wait_event_interruptible_timeout(
            wq, (timeout==0), timeout);
        printk("thread_code: woke up ...\n");
        if( timeout==-ERESTARTSYS ) {
            printk("got signal, break\n");
            break;
        }
    }
    thread_id = 0;
    complete_and_exit( &on_exit, 0 );
}
static int __init kthread_init(void)
{
    init_waitqueue_head(&wq);
    thread_id=kernel_thread(thread_code, NULL, CLONE_KERNEL );
    printk("thread_id %u",thread_id);
    if( thread_id==0 )
        return -EIO;
    return 0;
}
static void __exit kthread_exit(void)
{

printk("thread_code: exit ...\n");
printk("thread_id %u\n",thread_id);
    if( thread_id )
    {
        kill_pid( thread_id, SIGTERM, 1 );//kill_proc --> kill_pid
    }
    wait_for_completion( &on_exit );

}
module_init( kthread_init );
module_exit( kthread_exit );
MODULE_LICENSE("GPL");

At first I replaced kill_proc with kill_pid.

But if I run the programm and tip rmmod … I get this message:

thread_code: exit ...
thread_id 995
Unable to handle kernel paging request for data at address 0x000003eb
Faulting instruction address: 0xc0047998
Oops: Kernel access of bad area, sig: 11 [#1]
SBC8548
last sysfs file: 
Modules linked in: bsp_6_9(-)
NIP: c0047998 LR: c0040540 CTR: c0040578
REGS: cf987de0 TRAP: 0300   Not tainted  (2.6.36)
MSR: 00029000 <EE,ME,CE>  CR: 40000424  XER: 00000000
DEAR: 000003eb, ESR: 00000000
TASK = cf9fcdb0[997] 'rmmod' THREAD: cf986000
GPR00: 00000000 cf987e90 cf9fcdb0 000003e3 00000000 000003e3 c015b6c8 000023fc 
GPR08: 00000034 000003e3 000023fc c0040578 20000422 1004a180 00000240 00000000 
GPR16: 101042f0 1009ea94 100f0000 10043008 00000000 bf91a110 10001bcc bf91a11c 
GPR24: bf91a118 00000000 c02cca7c c02cca88 0000000f 00000001 000003e3 fffffffd 
NIP [c0047998] pid_task+0x18/0x38
LR [c0040540] kill_pid_info+0x2c/0x64
Call Trace:
[cf987e90] [c015b6c8] serial8250_console_putchar+0x0/0x4c (unreliable)
[cf987eb0] [d102a16c] kthread_exit+0x50/0x124 [bsp_6_9]
[cf987ed0] [c006026c] sys_delete_module+0x174/0x210
[cf987f40] [c000dae0] ret_from_syscall+0x0/0x3c
--- Exception: c01 at 0xff3b2bc
    LR = 0x10000f80
Instruction dump:
8127000c 90890004 3c000020 60000200 90030010 4e800020 2c030000 4082000c 
38600000 4e800020 5480103a 7d230214 <80690008> 2f830000 41beffe8 54892036 
---[ end trace d2ac023715aedf88 ]---
Segmentation fault
-bash-3.2# 

Message from syslogd@ at Thu Jan  1 01:00:10 1970 ...

MPC_Embedded_Linux kernel: last sysfs file: thread_code: woke up ...

Maybe the send kill_pid sequence is not right, but I found no solution.

  • 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-10T09:52:35+00:00Added an answer on June 10, 2026 at 9:52 am

    kill_pid takes a struct pid * as the first argument, not a pid_t (i.e. it takes a pointer to a process descriptor structure, not the process ID). You can look up the struct pid * using a function like find_vpid.

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

Sidebar

Related Questions

Quite experienced but self taught with PHP/MySQL and playing about with Rails. Really love
I'm trying to introduce a join to this query: SELECT `n`.*, round((`n`.`rgt` - `n`.`lft`
I understand why Python requires explicit self qualifier when referring to instance attributes. But
I'm trying to introduce a checkbox next to another element. The problem is that
This might be one of those questions that are difficult to answer, but here
I previously tried breaking this problem down into smaller, simpler problems here and here
I'm trying to introduce a logger in my project using Spring AOP, but I'm
I am trying to introduce pagination using the backbone.js paginator plugin 's requestPager .
I want to introduce a deterministic sorting to my [OWL] (http://www.w3.org/TR/owl-ref/) file so that
I want to introduce some random* behavior into an otherwise static html file. I

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.