insmod 명령어를 쓰면 lsmod에서 확인은 되는데 실행이 안되요...

bshsqa의 이미지

insmod hello.ko를 이용해서 모듈을 실행시켰는데...

lsmod에서 실행되는건 확인은 되는데요..

Hello!

라는 문장이 터미널에 뜨질 않네요..

컴파일도 성공했고... 실행도 되는거 같은데...

화면에 글이 안나오는 문제인데요..

이거 무엇을 잘못한 건가요?;;;

Prentice의 이미지

dmesg로는 확인해보셨나요..?

bshsqa의 이미지

[ 3366.384586] [Module Message] Hello, Module.
[ 3379.289982] [Module Message] Do you really want to break up with me?
[ 3389.297315] [Module Message] Hello, Module.
[ 3490.967338] [Module Message] Do you really want to break up with me?
[ 3506.262564] No module found in object
[ 3508.662287] [Module Message] Hello, Module.
[ 3588.908980] [Module Message] Do you really want to break up with me?
[ 3779.547087] [Module Message] Hello, Module.
[ 4005.337768] [Module Message] Do you really want to break up with me?
[ 4268.245339] Hellow
[ 4276.755801] Goodbye
[ 4279.725273] Hellow
[ 4299.176746] Goodbye
[ 4403.660252] Hellow
[ 4417.263115] Goodbye
[ 8471.025355] Hellow

맨 밑에 몇줄이 이렇게 나오긴 하는데요......

이것들이 제가 나오길 원했던 녀석들은 맞거든요?;;;

근데 왜 insmod로 했을때는 안 나오는 건가요?.ㅠ.ㅠ

송효진의 이미지

hellow 가 출력되는 위치가 stdout 이 아니기 때문이죠.
dmesg 에 출력되었잖아요.

emerge money
http://wiki.kldp.org/wiki.php/GentooInstallSimple - 명령어도 몇개 안되요~

bshsqa의 이미지

..ㅠ..ㅠ.

그면 stdout에 출력하게는 할수 없는 건가요?.

리눅스를 공부한게 아니라 갑자기 리눅스에 이케저케 해서 과제를 하세욤..

이라고 나온 덕에ㅠ.ㅠ. 시킨대로 그대로 따라했는데도 원하는게 안나와서 좌절한 상태였거든요.ㅠ.ㅠ.

터미널에 나오게 하려면 뭔가 수정해야 하는 건가요?

송효진의 이미지

현재 터미널은 /dev/stdout 인데, 모듈에서도 될것 같지는 않고,
/dev/fd/0 에 write 하면 broadcast 됩니다.
모든 터미널(콘솔)에 메세지가 출력됩니다.

emerge money
http://wiki.kldp.org/wiki.php/GentooInstallSimple - 명령어도 몇개 안되요~

bushi의 이미지

... 이대로 제출하면 F 맞습니다.

[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ cat hello2.c
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <asm/uaccess.h>
 
static struct file *my_filp = NULL;
 
static int printf(const char *fmt, ...)
{
        va_list args;
        char buf[128];
        unsigned int len;
        mm_segment_t fs;
        int ret;
        loff_t h = 0;
 
        va_start(args, fmt);
        len = vsnprintf(&buf[0], sizeof(buf) - 1, fmt, args);
        va_end(args);
        buf[len] = 0;
 
        fs = get_fs();
        set_fs(get_ds());
        ret = vfs_write(my_filp, &buf[0], len, &h);
        set_fs(fs);
 
        return ret;
}
 
inline int printf_init(void)
{
        struct task_struct *cur = get_current();
        /* -.-; */
        my_filp = filp_open("/proc/self/fd/1", O_WRONLY, 0);
        if (IS_ERR(my_filp)) {
                return PTR_ERR(my_filp);
        }
        get_file(my_filp);
        filp_close(my_filp, cur->files);
        return 0;
}
 
inline void printf_exit(void)
{
        fput(my_filp);
}
 
static int __init hello_init(void)
{
        int ret;
 
        ret = printf_init();
        if (ret < 0)
                return ret;
 
        printf("printf(): hello!\n");
        printk("printk(): hello!\n");
 
        return 0;
}
 
static void __exit hello_exit(void)
{
        printf_exit();
}
 
module_init(hello_init);
module_exit(hello_exit);
[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ make
make[1]: Entering directory `/usr/src/kernels/2.6.23.15-80.fc7-i686'
  CC [M]  /work/CVS/test/bushi/kernel_printf/hello2.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /work/CVS/test/bushi/kernel_printf/hello2.mod.o
  LD [M]  /work/CVS/test/bushi/kernel_printf/hello2.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.23.15-80.fc7-i686'
[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ sudo /sbin/insmod hello2.ko
printf(): hello!
[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ sudo tail -1 /var/log/messages
Apr  9 05:26:48 rose kernel: printk(): hello!
[bushi@rose kernel_printf]$ 
[bushi@rose kernel_printf]$ 

insmod 하는 과정동안만.
insmod 를 background 로 실행하지 않았다면.

OTL

Arcyze의 이미지

printk("<0> hello\n");

이렇게 출력하시면 아마 될겁니다.<0>은 메시지 파일에 씀과 동시에 터미널에 출력.

printk는 원래 로그데몬이 사용하는 메시지 파일에 쓰는걸로 알고 있고

dmesg는 그 메시지 파일을 출력해주는걸로 알고 있거든요 ^^;

<0> 부터 <6> 까지(맞나-_-;) 지정 가능 했던것 같네요. 나머지는 실험해보세요~

wkpark의 이미지

See also http://www.prabusurendra.com/tutors/lt2/lt2.html :>

"<0>"이면 시스템이 아주 위험하다는 메시지를 보낸다는 것이네요.

온갖 참된 삶은 만남이다 --Martin Buber

powerson의 이미지


일단 Arcyze님이 말씀하신 것처럼 printk의 LOG_LEVEL을 높여서 무조건 찍게끔 하는 방식이 있는데요. $KERNEL_SOURCE/include/linux/kernel.h에 보시면, KERNEL의 LOG_LEVEL에 대해서 8가지가 있습니다. 이걸 이용하셔도 되고, 만약 그게 싫으시다면, /etc/sysctl.conf에서 kernel.printk 정보를 수정하셔서 사용하셔도 됩니다. kernel.printk 역시 LOG_LEVEL 정보에 따라 터미널에도 뿌릴지를 결정하는 것이니, 참고하시면 될거 같습니다.

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.