Linux常见内核错误返回值宏定义

#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H

#define	EPERM		 1	/* Operation not permitted */
#define	ENOENT		 2	/* No such file or directory */
#define	ESRCH		 3	/* No such process */
#define	EINTR		 4	/* Interrupted system call */
#define	EIO		 	 5	/* I/O error */
#define	ENXIO		 6	/* No such device or address */
#define	E2BIG		 7	/* Argument list too long */
#define	ENOEXEC		 8	/* Exec format error */
#define	EBADF		 9	/* Bad file number */
#define	ECHILD		10	/* No child processes */
#define	EAGAIN		11	/* Try again */
#define	ENOMEM		12	/* Out of memory */
#define	EACCES		13	/* Permission denied */
#define	EFAULT		14	/* Bad address */
#define	ENOTBLK		15	/* Block device required */
#define	EBUSY		16	/* Device or resource busy */
#define	EEXIST		17	/* File exists */
#define	EXDEV		18	/* Cross-device link */
#define	ENODEV		19	/* No such device */
#define	ENOTDIR		20	/* Not a directory */
#define	EISDIR		21	/* Is a directory */
#define	EINVAL		22	/* Invalid argument */
#define	ENFILE		23	/* File table overflow */
#define	EMFILE		24	/* Too many open files */
#define	ENOTTY		25	/* Not a typewriter */
#define	ETXTBSY		26	/* Text file busy */
#define	EFBIG		27	/* File too large */
#define	ENOSPC		28	/* No space left on device */
#define	ESPIPE		29	/* Illegal seek */
#define	EROFS		30	/* Read-only file system */
#define	EMLINK		31	/* Too many links */
#define	EPIPE		32	/* Broken pipe */
#define	EDOM		33	/* Math argument out of domain of func */
#define	ERANGE		34	/* Math result not representable */

#endif


我们正常使用这些宏作为返回值时,要加上负号-

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 内核态编程中,创建线程可以通过以下步骤实现: 1. 包含必要的头文件:在源文件中包含 `<linux/kthread.h>` 头文件,该头文件提供了内核级线程相关的函数和宏定义。 2. 定义线程函数:编写一个函数,作为线程的入口点。该函数的原型应该是 `int thread_func(void *data)`,其中 `data` 参数可以用于传递线程需要的数据。 3. 创建内核线程:使用 `kthread_create()` 函数创建一个内核线程。该函数的原型为 `struct task_struct *kthread_create(int (*threadfn)(void *data), void *data, const char *namefmt, …)`。其中 `threadfn` 是线程函数的指针,`data` 是传递给线程函数的参数,`namefmt` 是线程的名称。 4. 启动内核线程:通过调用 `wake_up_process()` 函数来启动内核线程。该函数的原型为 `void wake_up_process(struct task_struct *tsk)`,其中 `tsk` 是通过 `kthread_create()` 创建的内核线程的返回值。 下面是一个简单的示例代码: ```c #include <linux/kthread.h> int my_thread_func(void *data) { // 线程要执行的操作 // ... return 0; } int init_module(void) { struct task_struct *thread; // 创建内核线程 thread = kthread_create(my_thread_func, NULL, "my_thread"); if (IS_ERR(thread)) { printk(KERN_ERR "Failed to create kernel thread\n"); return PTR_ERR(thread); } // 启动内核线程 wake_up_process(thread); return 0; } void cleanup_module(void) { // 清理模块 } ``` 请注意,内核线程的创建和管理需要特殊的权限和技巧。在编写和使用内核线程时,请确保了解相关的安全性和正确性问题,并遵循适当的编程和管理实践。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值