LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-12-2012, 01:45 PM   #1
rach_993
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Rep: Reputation: Disabled
How to get pointer of task_struct corresponding to a pid value.


Hi Guys,

I have written a kernel module code.where I have list of pid (process ids) stored in a Singular link list. I want to know if processes corresponding to its pids is alive or killed.in order to meet this requirement I need pointer of task_struct corresponding to the pid.

Also if any one know about what is namespace in linux OS??

Please help me.

Regards
Rach D
 
Old 06-13-2012, 01:45 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
Well one method I can think of, not very efficient though, is to loop through all the task_structs comparing the pids. If the processes that you have are related to each other ,that is they have a common parent then it will be easier .

Here is an example of how you can iterate over processes.
http://tuxthink.blogspot.in/2011/03/...roc-entry.html
 
1 members found this post helpful.
Old 06-13-2012, 02:00 AM   #3
rach_993
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks !! for the reply

Hey

Is it possible if we could travel in task_struct. I have pid but not relevant to any other pid. i have just a value of pid ,can i get pointer of task_struct using that pid value only if yes help me please

Regards

Rach D
 
Old 06-13-2012, 06:22 AM   #4
rach_993
LQ Newbie
 
Registered: Jun 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I found a way find_task_by_pid_ns()

Hi All,

Can any one let me know what that function working and how to use it to get task_struct pointer please help me !!!

Regards
Rach D
 
Old 06-14-2012, 12:48 PM   #5
micscherer
LQ Newbie
 
Registered: May 2011
Location: Vienna
Distribution: gentoo
Posts: 10

Rep: Reputation: 0
find_task_by_pid ( pid )

find_task_by_pid will return a pointer to a task_struct,
though it is now deprecated, because with namespaces it
will return only the task in an initial namespace.

you can use task_by_pid_ns and pass it the namespace
where your pid resides.

regards, michael
 
Old 06-26-2012, 01:43 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185Reputation: 3185
Best thing to do is to find the handler for some function-call, in the source code of your particular distribution, that uses a PID as one of its inputs. Trace through the code to find out how it's used. Copy that example, and of course, "Google it."
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Can I assign a Command to a specific PID so I can kill a predetermined PID johnmccarthy Linux - Newbie 1 11-03-2011 09:41 AM
reading pid from pid file in C language shifter Programming 1 05-14-2008 11:49 AM
kill pid.... won't work with 'pid' variable given.. sachitha Programming 6 03-06-2006 08:48 PM
/var/run/[XXX].pid - Tcl pid code liguorir Linux - Software 1 05-20-2004 11:32 PM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 09:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:20 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