Find the answer to your Linux question:
Results 1 to 2 of 2
I am trying to implement a system call in linux that performs a specifc functionality after some seconds have elapsed. For this pupose i use sys_alarm() in my system call ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    1

    Handling alarm signal in system call implementation


    I am trying to implement a system call in linux that performs a specifc functionality after some seconds have elapsed. For this pupose i use sys_alarm() in my system call and pass to it the number of seconds i want the process to wait. When the alarm goes off i call a handler function that is registered using sys_signal(). The problem is that whenever i invoke the system call through a user program, the user program gets stuck...Could you please go through the code and check what is missing ?

    #include <linux/linkage.h> //for linking a system call
    #include <linux/kernel.h>
    #include<linux/reboot.h>
    #include<linux/sched.h>
    #include<linux/time.h>
    #include<linux/signal.h>
    #include<linux/unistd.h>
    #include<linux/syscalls.h>


    volatile int keep_going = 1;

    void alarm_handler(int signal)
    {
    keep_going = 0;

    }

    asmlinkage long sys_myservice(int arg) {

    int delay=20;
    sys_signal(SIGALRM, alarm_handler);
    sys_alarm(20);

    while (keep_going){

    //do nothing
    }

    //write functionality here


    return 1;

    }

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,596
    What do you mean by "whenever i invoke the system call through a user program"? Are you trying to invoke the call directly? Have you written and installed a kernel module to handle the call from the user?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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