计操理论课04 -- openEuler实验第三章进程管理

本文详细介绍了如何在openEuler系统中进行进程管理,包括创建内核线程、打印CPU负载、获取运行进程信息以及利用cgroup限制CPU核数和阻止U盘访问。每个任务都包含具体的操作要求、代码实现和截图验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

任务1:创建并运行内核线程

任务要求

  1. 编写内核模块,创建一个内核线程;并在模块退出时杀死该线程。
  2. 加载、卸载模块并查看模块打印信息。

任务代码

kthread.c

#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/delay.h>

MODULE_LICENSE("GPL");

#define BUF_SIZE 20

static struct task_struct *myThread = NULL;

static int print(void *data)
{
   
	while(!kthread_should_stop()){
   
		printk("New kthread is running.");
		msleep(2000);
	}
	return 0;
}

static int __init kthread_init(void)
{
   
	printk("Create kernel thread!\n");
	myThread = kthread_run(print, NULL, "new_kthread");
	return 0;
}

static void __exit kthread_exit(void)
{
   
	printk("Kill new kthread.\n");
	if(myThread)
		kthread_stop(myThread);
}

module_init(kthread_init);
module_exit(kthread_exit);

Makefile

ifneq ($(KERNELRELEASE),)
	obj-m := kthread.o
else
	KERNELDIR ?= /usr/src/kernels/4.19.90
	PWD := $(shell pwd)
default:
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

血月无华AUV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值