Find the answer to your Linux question:
Results 1 to 7 of 7
in a simple kernel program I am trying to create a process using fork. I have included <linux/unistd.h> but it says the following error when I 'make' it. Is there ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    5

    fork() call not working in kernel programing ....!


    in a simple kernel program I am trying to create a process using fork. I have included <linux/unistd.h> but it says the following error when I 'make' it. Is there any alternative for the fork system call in kernel space.

    error: implicit declaration of function ‘fork’

  2. #2
    Just Joined!
    Join Date
    Jun 2009
    Posts
    5

    Wink

    Quote Originally Posted by Dissac View Post
    in a simple kernel program I am trying to create a process using fork. I have included <linux/unistd.h> but it says the following error when I 'make' it. Is there any alternative for the fork system call in kernel space.

    error: implicit declaration of function ‘fork’


    I think we should not be using fork in kernel space...since it has only event driven modules.... am I right?

  3. #3
    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,754
    I don't think you can fork a kernel "process". Any kernel module is part of the kernel, and you cannot fork the kernel itself. Why do you want to do this? And what are you trying to accomplish? If we knew that, perhaps we could suggest another approach to solving your problem.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Jun 2009
    Posts
    5
    I am trying to create a scenario for using semaphore. I wanted two processes to access a critical session and then protect it with a semaphore or mutex.

  6. #5
    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,754
    I think that if you are using ioctl to communicate with your kernel module, you don't need to worry about that since subsequent callers will queue until the module replies to the active caller. I am still getting up to speed in kernel programming so I might be wrong about that, but if I'm not, then if you need to protect a resource in your kernel module in a more persistent manner, you will need some means of registering the callers' process ids in your modules memory space. A linked list works well for that, and you won't need to use a semaphore. Just use a structure like this:
    Code:
    typedef struct pid_list_entry {
    pid_t client_pid;
    struct pid_list_entry* next;
    } pid_list_entry_t;
    
    typedef struct pid_list {
    pid_list_entry_t* head;
    pid_list_entry_t* tail;
    } pid_list_t;
    The head entry of the list would be the current holder of the resource. As more requests come in, you can allocate another entry and link them to the "next" of the tail entry. Anyway, this is pretty basic linked list stuff.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #6
    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,754
    BTW, there is a sys_fork() function defined in the kernel asm/unistd.h header file. What you need to do with that I cannot say. It takes a pointer to a structure with the register values contained. My guess is that this is the system call invoked when you call fork() from user space.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #7
    Just Joined!
    Join Date
    Jun 2009
    Posts
    5
    thanks for the info

Posting Permissions

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