kernel_thread问题,很初级,大家指教。
来源: 互联网 发布时间:2016-07-21
本文导语: #include #include #include #include #include #include #include #include static int execute(const char *string) { int ret; char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL, }; char *argv[] = { "/...
#include
#include
#include
#include
#include
#include
#include
#include
static int execute(const char *string)
{
int ret;
char *envp[] = {
"HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL,
};
char *argv[] = {
"/bin/bash",
"-c",
(char *)string,
NULL,
};
if ((ret =
call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC)) != 0) {
printk(KERN_ERR "run user application failed "%s": %in", string,
ret);
}
return ret;
}
int call_execute(char *str)
{
int ret;
ret = execute(str);
}
int print_string(char *fmt, ...)
{
struct tty_struct *current_tty = current->signal->tty;
char buf[200] = {0};
va_list va_str;
va_start(va_str,fmt);
vsprintf(buf,fmt,va_str);
va_end(va_str);
current_tty->ops->write(current_tty,buf,strlen(buf));
current_tty->ops->write(current_tty,"1215",6);
}
int print_string2(char *str)
{
struct tty_struct *current_tty = current->signal->tty;
current_tty->ops->write(current_tty,str,strlen(str));
current_tty->ops->write(current_tty,"1215",6);
}
int thread3(int i)
{
//print_string2("""this is thread 3n");
call_execute("/bin/touch /tmp/thread3; echo thread3 > /tmp/thread3;");
//printk("""printk this is thread 3n");
}
int thread2(int i)
{
//kernel_thread(thread3,4,CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
call_execute("/bin/touch /tmp/thread2; echo thread2 > /tmp/thread2;");
//print_string2("""this is thread 2n");
//printk("""printk this is thread 2n");
}
int thread1(int i)
{
// print_string2("""this is thread 1n");
call_execute("/bin/touch /tmp/thread1; echo thread1 > /tmp/thread1;");
// if(IS_ERR(kthread_run(thread2,4,"thread2")))
kernel_thread(thread2,4,CLONE_VFORK);
//call_execute("/bin/touch /tmp/thread4; echo thread4 > /tmp/thread4;");
//print_string2("""thread2 run failed");
}
static int mod_int()
{
int i = 0;
//if(IS_ERR(kthread_run(thread1, 9, "thread1")))
kernel_thread(thread1,4,CLONE_VFORK | CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
//kernel_thread(thread2,4,0);
}
void mod_exit()
{
print_string2("""module exitn");
}
module_init(mod_int);
module_exit(mod_exit);
现在问题,thread1可以产生,但是再产生thread2,就没有了,请问大家问题在哪?(我感觉是我的那个flag的问题,但又不知道哪个flag有问题,怎么解决)
#include
#include
#include
#include
#include
#include
#include
static int execute(const char *string)
{
int ret;
char *envp[] = {
"HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
NULL,
};
char *argv[] = {
"/bin/bash",
"-c",
(char *)string,
NULL,
};
if ((ret =
call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC)) != 0) {
printk(KERN_ERR "run user application failed "%s": %in", string,
ret);
}
return ret;
}
int call_execute(char *str)
{
int ret;
ret = execute(str);
}
int print_string(char *fmt, ...)
{
struct tty_struct *current_tty = current->signal->tty;
char buf[200] = {0};
va_list va_str;
va_start(va_str,fmt);
vsprintf(buf,fmt,va_str);
va_end(va_str);
current_tty->ops->write(current_tty,buf,strlen(buf));
current_tty->ops->write(current_tty,"1215",6);
}
int print_string2(char *str)
{
struct tty_struct *current_tty = current->signal->tty;
current_tty->ops->write(current_tty,str,strlen(str));
current_tty->ops->write(current_tty,"1215",6);
}
int thread3(int i)
{
//print_string2("""this is thread 3n");
call_execute("/bin/touch /tmp/thread3; echo thread3 > /tmp/thread3;");
//printk("""printk this is thread 3n");
}
int thread2(int i)
{
//kernel_thread(thread3,4,CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
call_execute("/bin/touch /tmp/thread2; echo thread2 > /tmp/thread2;");
//print_string2("""this is thread 2n");
//printk("""printk this is thread 2n");
}
int thread1(int i)
{
// print_string2("""this is thread 1n");
call_execute("/bin/touch /tmp/thread1; echo thread1 > /tmp/thread1;");
// if(IS_ERR(kthread_run(thread2,4,"thread2")))
kernel_thread(thread2,4,CLONE_VFORK);
//call_execute("/bin/touch /tmp/thread4; echo thread4 > /tmp/thread4;");
//print_string2("""thread2 run failed");
}
static int mod_int()
{
int i = 0;
//if(IS_ERR(kthread_run(thread1, 9, "thread1")))
kernel_thread(thread1,4,CLONE_VFORK | CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
//kernel_thread(thread2,4,0);
}
void mod_exit()
{
print_string2("""module exitn");
}
module_init(mod_int);
module_exit(mod_exit);
现在问题,thread1可以产生,但是再产生thread2,就没有了,请问大家问题在哪?(我感觉是我的那个flag的问题,但又不知道哪个flag有问题,怎么解决)
|
差不多.
int print_string(char *fmt, ...)
{
struct tty_struct *current_tty = current->signal->tty;
char buf[200] = {0};
va_list va_str;
va_start(va_str,fmt);
vsprintf(buf,fmt,va_str);
va_end(va_str);
//current_tty->ops->write(current_tty,buf,strlen(buf));
//current_tty->ops->write(current_tty,"1215",6);
printk("print_string1n");
}
int print_string2(char *str)
{
struct tty_struct *current_tty = current->signal->tty;
//current_tty->ops->write(current_tty,str,strlen(str));
//current_tty->ops->write(current_tty,"1215",6);
}
int thread3(int i)
{
//print_string2(" ""this is thread 3n");
call_execute("/bin/touch /tmp/thread3; echo thread3 > /tmp/thread3;");
//printk(" ""printk this is thread 3n");
}
int thread2(int i)
{
//kernel_thread(thread3,4,CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
//call_execute("/bin/touch /tmp/thread2; echo thread2 > /tmp/thread2;");
printk("this is thread 2n");
}
int thread1(int i)
{
printk("this is thread 1n");
//call_execute("/bin/touch /tmp/thread1; echo thread1 > /tmp/thread1;");
// if(IS_ERR(kthread_run(thread2,4,"thread2")))
kernel_thread(thread2,4,CLONE_VFORK);
//call_execute("/bin/touch /tmp/thread4; echo thread4 > /tmp/thread4;");
//print_string2(" ""thread2 run failed");
}
int print_string(char *fmt, ...)
{
struct tty_struct *current_tty = current->signal->tty;
char buf[200] = {0};
va_list va_str;
va_start(va_str,fmt);
vsprintf(buf,fmt,va_str);
va_end(va_str);
//current_tty->ops->write(current_tty,buf,strlen(buf));
//current_tty->ops->write(current_tty,"1215",6);
printk("print_string1n");
}
int print_string2(char *str)
{
struct tty_struct *current_tty = current->signal->tty;
//current_tty->ops->write(current_tty,str,strlen(str));
//current_tty->ops->write(current_tty,"1215",6);
}
int thread3(int i)
{
//print_string2(" ""this is thread 3n");
call_execute("/bin/touch /tmp/thread3; echo thread3 > /tmp/thread3;");
//printk(" ""printk this is thread 3n");
}
int thread2(int i)
{
//kernel_thread(thread3,4,CSIGNAL | CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_PTRACE | CLONE_IO);
//call_execute("/bin/touch /tmp/thread2; echo thread2 > /tmp/thread2;");
printk("this is thread 2n");
}
int thread1(int i)
{
printk("this is thread 1n");
//call_execute("/bin/touch /tmp/thread1; echo thread1 > /tmp/thread1;");
// if(IS_ERR(kthread_run(thread2,4,"thread2")))
kernel_thread(thread2,4,CLONE_VFORK);
//call_execute("/bin/touch /tmp/thread4; echo thread4 > /tmp/thread4;");
//print_string2(" ""thread2 run failed");
}