LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2005, 06:48 AM   #1
yhus
Member
 
Registered: May 2004
Posts: 75

Rep: Reputation: 15
kernel thread


Hello,

I want to create a new task in kernel space and using following function call:

int NewTask(void *arg)
{
while(1)
{
......;
Sleep(10);
}
}

int CreateTask(void)
{
......
kernel_thread(NewTask, &parameter, CLONE_KERNEL);
return 0;
}

The NewTask was called, but the CreatTask function did not return, it blocked at the function of kernel_thread(). What was wrong with the kernel_thread? Should it just create another thread and let the parent thread exits?

Thank you

Last edited by yhus; 08-04-2005 at 06:50 AM.
 
Old 08-04-2005, 07:23 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
I'll try and explain what should happen here.....

So kernel_thread basically calls clone() with specified arguements (usually CLONE_FS, CLONE_FILES, and CLONE_SIGHAND which is what CLONE_KERNEL implies). The kernel thread will then have context and execute. Sometime later, when the parent kernel thread gets context again, it should exit peacefully with a pointer to the child threads task_struct.

Is your "NewTask" kernel thread ever giving up context? or does the machine just lock up or something?

BTW, since this is more of a programming type question I'm going to go ahead and move it to the programming forum.
 
Old 08-04-2005, 04:30 PM   #3
yhus
Member
 
Registered: May 2004
Posts: 75

Original Poster
Rep: Reputation: 15
Thanks jtshaw. The NewTask should run on background until the state is changed. The parent thread should exit peacefully, but since the parent thread bloked at kernel_thread() call, the other code after the kernel_thread() cannot run, so the machine was kind of locked up. What I was missing here? Why the parent thread in CreateTask() blocked at kernel_thread function call?

Thank you.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how does the kernel decide which thread gets the cpu? Thinking Programming 8 10-19-2005 12:22 PM
kernel thread and signal handling oriate Linux - General 3 10-18-2005 12:41 PM
kernel thread and blocking calls asurya Linux - General 1 09-22-2005 11:15 PM
what advantage do kernel thread has over process? keiwu Linux - Software 1 03-04-2005 07:18 PM
obtain pid of a kernel thread ratwings Linux - Software 0 02-11-2005 03:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration