Page 1 of 1

Reading process info (task_struct) in user mode(LINUX)

Posted: Mon Nov 26, 2007 3:24 pm
by wreckedpc
Hello All,

I am completely new to Kernel Programming. Hence I will explain my requirements. I will greatly appreciate if anyone of you can help me out.

OS : Linux

Problem : To read signal information (Signal Mask , pending signals etc) of a particular process. We know pid of that process. This will be done from user mode.

My Approach: To read another process' task_struct structure (which contains essential information related to particular process) from kernel and use this information.

Roadblock: I checked /linux/sched.h . I saw a function find_task_by_pid. This function takes pid as an argument and returns task_struct of that process. But merely inclusion of this file(#include) in my code gave me millions of errors.

I will be grateful if you help me out with this. Pardon me if I have missed details , but I will be glad to provide more.

Posted: Tue Nov 27, 2007 2:50 am
by AJ
Hi,

AFAIK, you can't do this from user mode (ring 3). You need to be a privileged process. One way to get around this would be to write your program as a driver rather than an application. Does writing a driver(/module) fit in with whatever you are trying to do?

If Linux were to let you directly run that kernel code from application-space, any program (think virusses etc...) could execute kernel code and compromise system security and stability.

Disclaimer: I am speaking from the point of view of someone who is programming an OS and am not a Linux expert.

HTH
Adam

Posted: Fri Nov 30, 2007 2:41 am
by mystran
AJ wrote: If Linux were to let you directly run that kernel code from application-space, any program (think virusses etc...) could execute kernel code and compromise system security and stability.
Well not quite. You can gives read access without giving write access, but it is true that confidentiality would be violated. Then again, root can already do whatever he pleases, so... well..

Anyway, there's a simple way: run ps with the relevant option, grep for the process you're interested, awk the signal masks if you want to get rid of the other stuff in the listing. No need to do any programming :)