gpt4 book ai didi

c - 在 linux 2.6.39.4 内核中测试系统调用

转载 作者:行者123 更新时间:2023-12-04 05:48:42 24 4
gpt4 key购买 nike

我正在发出一个新的系统调用来获取 FCFS 调度的平均等待时间。
我将系统调用名称命名为“add2”。现在在成功编译内核后,我在测试系统调用时遇到问题。

通过一些研究,我想出了这两个程序来测试我的系统调用。但是这些仍然存在一些问题。我认为问题在于传递参数。请帮忙。

这是 addnewsystemcall.h

#include<linux/unistd.h>
#define __NR_add2 307


long add2(int at[], int bt[], int n)
{
return syscall(__NR_atvfcfs,i);
}

这是 addnewsystemcall.c
#include<string.h>
#include <stdio.h>
#include "add2.h"


int main()
{
int avgwt;

int n,i,at[50],bt[50];

printf("\n\nEnter the number of processes:");
scanf("%d",&n);
printf("\n\n BURST TIME and ARRIVAL TIME of thr process");

for(i=0;i<n;i++)
{
printf("\n ARRIVAL TIME :");
scanf("%d",&at[i]);
printf(" BURST TIME : ");
scanf("%d",&bt[i]);
}

printf("\n\nAverage waiting time = ");
printf("%d\n", add2(int at[], int bt[], int n));
return 0;
}

最佳答案

添加系统调用是从内核获取信息最困难的方法。不要这样做,除非你真的需要。

有很多更好的方法,例如:
1.在/proc下添加虚拟文件或 /sys .这为您提供了一个非常易于使用的文本界面。
2. 添加设备驱动,创建/dev文件并使用 ioctl功能。这更难使用,但可能更适合传递二进制结构。

关于c - 在 linux 2.6.39.4 内核中测试系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10364270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com