I am new to Linux programming, and I am stuck in trouble when programming a loadable kernel module for the Operating System course. In this task, I need to create a kernel thread when initializing the module, and then run a function. Within the function, a child process should be created by using _do_fork() routine defined in kernel/fork.c. The parameter list of _do_fork is as below:
long _do_fork(unsigned long clone_flags,
unsigned long stack_start,
unsigned long stack_size,
int __user *parent_tidptr,
int __user *child_tidptr,
unsigned long tls)
My question is how to fill out the parameter "stack_start"? I know it specifies the location of stack which is used by the child process. Any one can give me an example of how to use _do_fork()?
Here attaches part of my code:
static struct task_struct *task;
int my_fork(void *argc){
long pid = 0;
/* fork a process using do_fork */
pid = _do_fork(SIGCHLD, ???, 0, NULL, NULL, 0);
printk("This is child process with pid %ld\n", pid);
return 0;
}
static int __init program2_init(void){
printk("[program2] : Module_init\n");
/* create a kernel thread to run my_fork */
task = kthread_create(&my_fork, NULL, "GoodThread");
// wake up the thread
if (!IS_ERR(task)) {
printk("kthread starts\n");
wake_up_process(task);
}
return 0;
}
And requirement in this assignment is attached:
When program2.ko being initialized, create a kernel thread and run my_fork function. (10 points) Within my_fork, fork a process to execute the test program. (10 points)
Hints: 1) Use “_do_fork” to fork a new process. (/kernel/fork.c)
Thanks a lot!!!
_do_fork. And you still need to explain what is your kernel module intended to do - Basile Starynkevitch