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.
- 06-06-2009 #1Just 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’
- 06-07-2009 #2Just Joined!
- Join Date
- Jun 2009
- Posts
- 5
- 06-07-2009 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
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!
- 06-08-2009 #4Just 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.
- 06-08-2009 #5Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
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:
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.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;Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 06-10-2009 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
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!
- 06-12-2009 #7Just Joined!
- Join Date
- Jun 2009
- Posts
- 5
thanks for the info


Reply With Quote

