C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-14-2009, 09:50 AM   #1
Registered User
 
Join Date: Apr 2009
Posts: 2
Question Linux Programming, reading the PCB

Hi guys,

i am not new into C Programming, but i am new into programming or modifying the linux kernel. For my study I have to write a little program now that reads every processes in the PCB and extracts the cpu-time from them. If the process exceeds a given time-limit i have to kill it. Sounds like a stupid task, but I didn't made it up

What we arent allowed to do is simply writing a bash script that uses "ps" or writing a c-program that reads the /proc directory.

My question now is: Where do I start?
What I have done so far is: I thought i could make a kernel module, I read a module programming guide and my kernel module compiles so far and i can insmod it into my kernel. We aren't allowed to write a normal userspace program, we have to modify the kernel or write a kernel module that does the work.

I hope you can help, thanks a lot!
Deadgentoo is offline   Reply With Quote
Old 04-14-2009, 10:02 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
In one way it's a stupid task, because there are other ways that you could do this, which are safer, more portable and already exists. But in the sense that you learn how kernel code works, it's a good task.

So, the questions that I'd be looking at is:
1. If you are using a kernel module, how can you get to the PCB from whatever information you give to the kernel driver about the process?
2. How do you kill a process?

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 04-14-2009, 10:06 AM   #3
Registered User
 
Join Date: Apr 2009
Posts: 2
1) i dunno
2) man 2 kill gives some usefull informations.
#include <sys/types.h>
#include <signal.h>

int kill(pid_t pid, int sig);
Deadgentoo is offline   Reply With Quote
Old 04-14-2009, 10:10 AM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
But kill is a user-mode method, you can not do that from a kernel module.

I'm not asking questions that I necessarily know the answer to, but I am asking questions that I believe, if you know the answer, you will be well under way solving the problem.

This site is invaluable when working on the Linux kernel.
LXR / The Linux Cross Reference

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WIN32 API and Linux... *shudder parad0x13 C++ Programming 4 07-24-2008 07:27 PM
How can I compile C and C++ in Linux operating system? Please help. MarkSquall C Programming 8 03-10-2008 12:08 PM
Linux for Windows! Strut Linux Programming 2 12-25-2002 11:36 AM
Linux? Windows Xp? VooDoo Linux Programming 15 07-31-2002 08:18 AM
linux vs linux? Dreamerv3 Linux Programming 5 01-22-2002 09:39 AM


All times are GMT -6. The time now is 07:21 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22