私は kthreads に慣れようとしており、http://tuxthink.blogspot.com/2011/02/kernel-thread-creation-1.html のガイダンスに従って、C でテストするための非常に単純なプログラムを作成しました。MacOSX の VMware で Ubuntu を実行しています。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "cycle.h"
#include <linux/kthread.h>
#include <linux/sched.h>
int main(){
static struct task_struct *kthread;
thread1 = kthread_create(thread_fn, NULL, "thread1");
wake_up_process(thread1);
kthread_stop(thread1);
return 0;
}
gcc (gcc test5.c -o test5.out) を使用してこれをコンパイルしようとすると、「致命的なエラー: linux/kthread.h: そのようなファイルまたはディレクトリのコンパイルは終了しませんでした」というメッセージが表示されます。
/usr/include/linux/ を調べてみると、kthread.h ファイルがないので、妥当なようです。kthread.hi を検索すると、/usr/src/linux-headers-3.2.0-31/include/linux に 1 つ、/usr/src/linux-headers-3.2.0-29/include/linux に 1 つ見つかりますが、そのうちの 1 つを /usr/include/linux/ にコピーしようとした後、エラー メッセージが表示され続けます。
In file included from /usr/include/linux/kthread.h:4:0,
from test5.c:5:
/usr/include/linux/err.h:22:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_PTR’
/usr/include/linux/err.h:27:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_ERR’
/usr/include/linux/err.h:32:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR’
/usr/include/linux/err.h:37:33: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘IS_ERR_OR_NULL’
/usr/include/linux/err.h:49:35: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘ERR_CAST’
/usr/include/linux/err.h:55:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘PTR_RET’
In file included from test5.c:5:0:
/usr/include/linux/kthread.h:7:10: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:7:13: error: expected declaration specifiers or ‘...’ before numeric constant
/usr/include/linux/kthread.h:58:2: error: unknown type name ‘spinlock_t’
/usr/include/linux/kthread.h:59:19: error: field ‘work_list’ has incomplete type
/usr/include/linux/kthread.h:64:19: error: field ‘node’ has incomplete type
/usr/include/linux/kthread.h:66:2: error: unknown type name ‘wait_queue_head_t’
/usr/include/linux/kthread.h:67:2: error: unknown type name ‘atomic_t’
/usr/include/linux/kthread.h:128:1: error: unknown type name ‘bool’
test5.c: In function ‘main’:
test5.c:11:2: error: ‘thread1’ undeclared (first use in this function)
test5.c:11:2: note: each undeclared identifier is reported only once for each function it appears in
test5.c:11:12: error: ‘thread_fn’ undeclared (first use in this function)
これを解決する方法についてのアイデアは非常に高く評価されます!