Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux系统在运行make时调用C代码错误_C_Linux_Makefile_Virtualbox_System Calls - Fatal编程技术网

Linux系统在运行make时调用C代码错误

Linux系统在运行make时调用C代码错误,c,linux,makefile,virtualbox,system-calls,C,Linux,Makefile,Virtualbox,System Calls,有人知道我为什么会出现这些错误,或者如何修复这些错误以使make正常运行吗?该代码应该是一个静态系统调用,以合并到我的自定义Linux内核中。系统调用应采用一个参数并返回该进程、其子进程、子线程和同级进程的进程状态信息。有人告诉我,一旦我写完我的C代码,我必须先运行make,然后再运行make安装,但每次运行make时,我都会遇到同样的错误,我不知道如何修复它们。我正在使用CentOS VirtualBox。请提供帮助。是否安装了内核头文件?比如,yum-install-kernel-devel

有人知道我为什么会出现这些错误,或者如何修复这些错误以使make正常运行吗?该代码应该是一个静态系统调用,以合并到我的自定义Linux内核中。系统调用应采用一个参数并返回该进程、其子进程、子线程和同级进程的进程状态信息。有人告诉我,一旦我写完我的C代码,我必须先运行make,然后再运行make安装,但每次运行make时,我都会遇到同样的错误,我不知道如何修复它们。我正在使用CentOS VirtualBox。请提供帮助。

是否安装了内核头文件?比如,
yum-install-kernel-devel
?不,我在进行系统调用之前这样做了,在创建系统调用之后,我必须再次执行所有这些操作?这里缺少很多东西
MAX_RT_PRIO
来自CentOS 7.3上的
/linux/sched/RT.h
。但不包括在内。安装内核头,调整源代码和makefile,然后重试。好的,谢谢你的帮助,我认为我没有安装头,所以我现在就试试,然后再试一次。你得到的代码不能用于此版本的Linux内核。花些时间阅读内核编程,然后准备修改源代码和makefile.:)
#include <linux/linkage.h>
#include <linux/pinfo.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <asm/current.h>
#include <linux/sched.h>

#define NSEC 1000000000
#define time_cal(t) \
t->start_time.tv_sec * NSEC + t->start_time.tv_nsec

// Prototype functions
int get_PID(void);
long get_state(void);
long get_nice(void);
unsigned long get_start_time(void);
int get_parent_id(void);
int get_children(void);
int get_youngest_child(void);
int get_younger_silbing(void);
int get_older_sibling(void);
long get_user_time(void);
long get_sys_time(void);
char * get_comm(void);
long get_UID(void);

// Global var used to get the task struct
struct task_struct *get_t;

// Process ID
int get_PID(void){
    return get_t->pid;
}

// Current state of process (-1 unrunnable, 0 runnable, >0 stopped)
long get_state(void){
return get_t->state;
}

// Process nice value range from -20 <> 19 (high prio neg values & lower 
prio pos values)
long get_nice(void){
return (get_t->prio - MAX_RT_PRIO - 20);
}

// Process id of parent
int get_parent_id(void){
return get_t->parent->pid;
}

// Total number of children
int get_children(void){
struct list_head *tmp;
int i = 0;
// Traverse the doubly linked list to get the number of children
list_for_each(tmp, &get_t->children){ ++i; }
// no children then return -1
if(i == 0){ return -1; }
else{ return i; }
}

// PID of the youngest child
int get_youngest_child(void){
// get the list of childrens
struct list_head *tmp = &get_t->children;
int pid;
if(&tmp == NULL){ return -1; }
// use macro to get the task_struck embedded
// Note: list_entry( ptr, type, member)
pid = list_entry(tmp->prev, struct task_struct, children)->pid;
// if list_entry ret is zero or the pid is the same as its self then return 
-1
if(pid == 0 || pid == get_PID()){return -1;}
return pid;
}

// PID of younger sibling
int get_younger_sibling(void){
// get the list of siblings
struct list_head *tmp = &get_t->sibling;
int pid;
if(&tmp == NULL){return -1;}
// use macro to get the task_struck embedded
// Note: list_entry( ptr, type, member)
pid = list_entry(tmp->next, struct task_struct, sibling)->pid;
// if list_entry ret is zero or the pid is the same as its self then return 
-1
if(pid == 0 || pid == get_PID()) {return -1;}
return pid;
}

// PID of older sibling
int get_older_sibling(void){
// get the list of sibling
struct list_head *tmp = &get_t->sibling;
int pid;
if(&tmp == NULL){return -1;}
// use macro to get the task_struck embedded
// Note: list_entry( ptr, type, member)
pid = list_entry(tmp->prev, struct task_struct, sibling)->pid;
// if list_entry ret is zero or the pid is the same as its self then return 
-1
if(pid == 0 || pid == get_PID()) {return -1;}
return pid;
}

// Process start time
unsigned long get_start_time(void){
return time_cal(get_t);
}

// CPU time spent in user mode
long get_user_time(void){
return get_t->utime;
}

// CPU time spent in system mode
long get_sys_time(void){
return get_t->stime;
}

// User id of process owner
long get_UID(void){
return get_t->uid;
}

// Name of program executed
char * get_comm(void){
return get_t->comm;
}

asmlinkage long sys_pinfo(struct pinfo *process){
// if the user didn't provide stack or heap space then return -22
if(&process == NULL){return -22;}

// Fill in the Process Information
get_t = get_current();
process->pid = get_PID();
process->state = get_state();
process->nice = get_nice();
process->parent_pid = get_parent_id();
process->children = get_children();
process->youngest_child_pid = get_youngest_child();
process->younger_sibling_pid = get_younger_sibling();
process->older_sibling_pid = get_older_sibling();
process->start_time = get_start_time();
process->user_time = get_user_time();
process->sys_time = get_sys_time();
process->uid = get_UID();
strcpy(process->comm, get_comm());
return 0;
}
pinfo/pinfo.c: In function ‘get_nice’:
pinfo/pinfo.c:44:24: error: ‘MAX_RT_PRIO’ undeclared (first use in this 
function)
return (get_t->prio - MAX_RT_PRIO - 20);
                    ^
pinfo/pinfo.c:44:24: note: each undeclared identifier is reported only once 
for each function it appears in
pinfo/pinfo.c: In function ‘get_youngest_child’:
pinfo/pinfo.c:68:10: error: the comparison will always evaluate as ‘false’ 
for the address of ‘tmp’ will never be NULL [-Werror=address]
if(&tmp == NULL){ return -1; }
      ^
pinfo/pinfo.c: In function ‘get_younger_sibling’:
pinfo/pinfo.c:82:10: error: the comparison will always evaluate as ‘false’ 
for the address of ‘tmp’ will never be NULL [-Werror=address]
if(&tmp == NULL){return -1;}
      ^
pinfo/pinfo.c: In function ‘get_older_sibling’:
pinfo/pinfo.c:96:10: error: the comparison will always evaluate as ‘false’ 
for the address of ‘tmp’ will never be NULL [-Werror=address]
if(&tmp == NULL){return -1;}
      ^
pinfo/pinfo.c: In function ‘get_UID’:
pinfo/pinfo.c:122:14: error: ‘struct task_struct’ has no member named ‘uid’
return get_t->uid;
          ^
pinfo/pinfo.c: In function ‘sys_pinfo’:
pinfo/pinfo.c:132:14: error: the comparison will always evaluate as ‘false’ 
for the address of ‘process’ will never be NULL [-Werror=address]
if(&process == NULL){return -22;}
          ^
pinfo/pinfo.c:140:9: error: ‘struct pinfo’ has no member named ‘children’
process->children = get_children();
     ^
pinfo/pinfo.c: In function ‘get_nice’:
pinfo/pinfo.c:45:1: error: control reaches end of non-void function [- 
Werror=return-type]
}
^

pinfo/pinfo.c: In function ‘get_UID’:
pinfo/pinfo.c:123:1: error: control reaches end of non-void function [- 
Werror=return-type]
}
^

cc1: all warnings being treated as errors
make[1]: *** [pinfo/pinfo.o] Error 1
make: *** [pinfo] Error 2