Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question How to block a process in kernel

    Hi guys, I'm writing a simple module which can tell a user process if something happens in kernel. Specifically, inside my module, I declare a symbol:
    void *pointer = NULL;
    Now, I want to tell some process in userspace when this pointer is not NULL. I did that by doing the following:
    In user space
    devfd = open("/dev/my_dev",O_RDWR);
    //my_dev is a fake character device I created

    In kernel space
    switch CONSTANT
    case CHECK_POINTER: while(pointer==NULL){}
    return 0;

    My intention is letting the kernel blocks ioctl while pointer is NULL and returns immediately when pointer is not NULL. However, this way makes my computer hangs. Do you guys have any better idea to block ioctl.

  2. #2
    Linux User fernape's Avatar
    Join Date
    Dec 2005
    The hangs comes from this:

    Quote Originally Posted by LegolasV
    Maybe you need a kind of signaling mechanism. What if your user-space programs checks periodically the /dev/my_dev file until it gets the proper value?

    Best regards

  3. #3
    The best way that I know of to signal a user-mode from kernel-mode is to use signalling. That is equivilent to a user-mode interrupt. You hook a signal and when someone taps that signal for your process, your registered callback function is called.

    This taken (cut) from some project I did a couple of years. It is probably missing some stuff, but should be enough to get you going.

    For user-mode look at usage for functions:

    sigaction act;
    sigset_t signalsUsed;

    act.sa_handler = CallBackFunc;
    sigemptyset( &act.sa_mask );
    sigaction(SIGINT, &act, 0);
    sigaction( YourSignalNo, &act, 0);
    //use this to get task id for kernel mode signalling
    pid=getpid(); //pass this to your kernel module for use down below

    //Signal handler
    void CallBackFunc(int signum)
    sigprocmask(SIG_BLOCK, &signalsUsed, NULL);
    printf("SIGNAL RECEIVED:%d\n",signum);

    if ( signum == SIGINT )
    goto EXIT_NOW;

    //Do your work here

    sigprocmask(SIG_UNBLOCK, &signalsUsed, NULL);

    For kernel mode, call this to interrupt user-mode (first parm is your signal no, second is the result from calling find_task_by_pid(pid) obtained from the user-mode call getpid() function):

    //Interrupt signal owner (user-mode in this case)
    extern int send_sig(int, struct task_struct *, int); //kernel function

    Hope this helps.


  4. $spacer_open
  5. #4
    thanks for your reply. I found that wake_up() and sleep() also solves the problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts