[lkml]   [2002]   [Sep]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjectkthread execve question

HI !

starting out at kernel/kmod.c as an example I tried to execve a simple command
from a kernel thread using the exec_usermodehelper from kmod (kmod enabled in
the kernel). It all seems to be fine - the printk appears but the command is
not executed...

any hint whats wrong ? any pointers to using kernel threads dosc/examples in
general and how to execute user space apps would be appreciated.

thx !

--- broken hello world kthread ---

#include <linux/config.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/unistd.h>
#include <linux/kmod.h>
#include <linux/smp_lock.h>

#include <asm/uaccess.h>

char cmd_path[256] = "/bin/echo";

static int exec_cmd(void * kthread_arg)
static char * envp[] = { "HOME=/",
char *argv[] = { kthread_arg,
int ret;

printk("calling usermodehelper for %s \n",cmd_path);
ret = exec_usermodehelper(cmd_path, argv, envp);

printk(KERN_ERR "failed to exec %s, ret = %d\n", cmd_path,ret);
return ret;

int init_module(void) {
pid_t pid;
char kthread_arg[]="Hello World";

pid = kernel_thread(exec_cmd, (void*) kthread_arg, 0);
if (pid < 0) {
printk(KERN_ERR "fork failed, errno %d\n", -pid);
return pid;
printk("fork ok, pid %d\n",pid);
return 0;

void cleanup_module(void) {
printk("module exit\n");
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:28    [W:0.042 / U:4.952 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site