Thread: Linux Programming, reading the PCB

  1. #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!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  3. #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);

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIN32 API and Linux... *shudder
    By parad0x13 in forum C++ Programming
    Replies: 4
    Last Post: 07-24-2008, 07:27 PM
  2. Replies: 8
    Last Post: 03-10-2008, 12:08 PM
  3. Linux for Windows!
    By Strut in forum Linux Programming
    Replies: 2
    Last Post: 12-25-2002, 11:36 AM
  4. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM
  5. linux vs linux?
    By Dreamerv3 in forum Linux Programming
    Replies: 5
    Last Post: 01-22-2002, 09:39 AM