执行系统调用时出现问题,系统调用未向内核显示
Problem doing a system call, the system call is not displaying to kernel
在Ubuntu中,我写了一个新的系统调用:
SYSCALL_DEFINE1(print_other, pid_t, targetpid)
{
struct task_struct *p;
int found = 0;
for(p = &init_task; next_task(p) != &init_task; p=next_task(p))
{
if(p->pid == targetpid)
{
found = 1;
break;
}
}
if (found)
{
for(p = current; p != &init_task; p = p->parent)
{
printk("Task:\n");
printk("Process ID: %d\n", p->pid);
printk("Running state: %ld\n", p->state);
printk("Program name: %s\n", p->comm);
printk("Start time: %llu\n", p->start_time);
printk("Virtual runtime: %llu\n\n", p->se.vruntime);
}
}
else
{
printk("Your process was not found");
}
return 0;
}
这是我的测试文件:
#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define __NR_print_other 337
int main(int argc, char *argv[])
{
char search[10];
char *error;
pid_t in_pid;
unsigned long pid;
while (true)
{
printf("Enter PID to search: ");
scanf("%s", search);
printf("passed scanf\n");
pid = strtoul(search, &error, 10);
printf("passed strtoul\n");
if (*error || error == argv[1] || ((pid_t)pid != pid ||
(pid_t)pid <= 0))
{
printf("in if statement\n");
printf("\nError: Invalid PID entered\n");
printf("Try again\n");
}
else
{
printf("in else statement\n");
in_pid = pid;
syscall(__NR_print_other, in_pid);
printf("about to return, in_pid = %d\n", in_pid);
return 0;
}
}
}
但是测试文件是好的。系统调用没有做任何事情,我不明白为什么。我做错了应该怎么办?
我真的没有什么可找的了。我检查了测试文件,它运行正常。它 returns in_pid 是正确的并且正确运行错误边界检查。系统调用中一定存在逻辑错误,但我看不出问题出在哪里。
您的系统调用正在运行并正在做一些事情。只是 运行 dmesg
你应该会看到类似这样的东西:
[ 3755.306897] Task:
[ 3755.306898] Process ID: 1
[ 3755.306899] Running state: 1
[ 3755.306900] Program name: systemd
[ 3755.306902] Start time: 371331827
[ 3755.306903] Virtual runtime: 1757840935
在Ubuntu中,我写了一个新的系统调用:
SYSCALL_DEFINE1(print_other, pid_t, targetpid)
{
struct task_struct *p;
int found = 0;
for(p = &init_task; next_task(p) != &init_task; p=next_task(p))
{
if(p->pid == targetpid)
{
found = 1;
break;
}
}
if (found)
{
for(p = current; p != &init_task; p = p->parent)
{
printk("Task:\n");
printk("Process ID: %d\n", p->pid);
printk("Running state: %ld\n", p->state);
printk("Program name: %s\n", p->comm);
printk("Start time: %llu\n", p->start_time);
printk("Virtual runtime: %llu\n\n", p->se.vruntime);
}
}
else
{
printk("Your process was not found");
}
return 0;
}
这是我的测试文件:
#include <linux/unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define __NR_print_other 337
int main(int argc, char *argv[])
{
char search[10];
char *error;
pid_t in_pid;
unsigned long pid;
while (true)
{
printf("Enter PID to search: ");
scanf("%s", search);
printf("passed scanf\n");
pid = strtoul(search, &error, 10);
printf("passed strtoul\n");
if (*error || error == argv[1] || ((pid_t)pid != pid ||
(pid_t)pid <= 0))
{
printf("in if statement\n");
printf("\nError: Invalid PID entered\n");
printf("Try again\n");
}
else
{
printf("in else statement\n");
in_pid = pid;
syscall(__NR_print_other, in_pid);
printf("about to return, in_pid = %d\n", in_pid);
return 0;
}
}
}
但是测试文件是好的。系统调用没有做任何事情,我不明白为什么。我做错了应该怎么办?
我真的没有什么可找的了。我检查了测试文件,它运行正常。它 returns in_pid 是正确的并且正确运行错误边界检查。系统调用中一定存在逻辑错误,但我看不出问题出在哪里。
您的系统调用正在运行并正在做一些事情。只是 运行 dmesg
你应该会看到类似这样的东西:
[ 3755.306897] Task:
[ 3755.306898] Process ID: 1
[ 3755.306899] Running state: 1
[ 3755.306900] Program name: systemd
[ 3755.306902] Start time: 371331827
[ 3755.306903] Virtual runtime: 1757840935