print_string + kernel_thread 这样就可以在多线程的情况下通过telnet打消息到当前的终端

#include <stdarg.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/tty.h>
#include <linux/kthread.h>
#include <linux/kmod.h>
#include <stdarg.h>

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,"/012/015",2);

}

int
thread3 (int i)
{
  printk ("this is thread 3/n");
  print_string ("string this is thread 3/n");
  return 1;
}
int
thread2 (int i)
{
  kernel_thread (thread3, 4, 0);
  printk ("this is thread 2/n");
  print_string ("string this is thread 2/n");
}

int
thread1 (int i)
{
  kernel_thread (thread2, 4, 0);
  printk ("this is thread 1/n");
  print_string ("string this is thread 1/n");
}


static int mod_int()
{
int i = 0;
kernel_thread(thread1,4,0);
printk("module insert/n");
return 0;
}

void mod_exit()
{
printk("module exit/n");
}

module_init(mod_int);
module_exit(mod_exit);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值