我对C还是比较陌生,在创建我的程序之一时,我有一个结构,在子进程中,我更改了该结构的某些属性,但我希望它能反映实际的结构。在我的代码的简化版本中,我的主要函数创建一个名为table的结构,并根据用户输入设置其所有属性,然后在maketable函数中,子进程会将状态更改为1,在这种情况下,这意味着程序将被执行不久,调用runprogram运行table.program
struct task{
int id; // id of the task
int pid_t pid;
int status = 0;
JOB* program; // arguments of a program to run EX:sleep 30
}
void print_task_info(){
// prints all attributes of task to stdout
}
void getcommand(){
//makes a task struct and initializes it from user input
//then calls maketable
}
void maketable(struct task table){ // is called inside getcommand()
pid_t p;
if((p = fork()) == 0){
table.status = 1;
runprogram(table); // runs the task using execvp
}else
getcommand(); // getcommand() basically gets an id and calls maketable
}
我想将table.status更新为1,但结果显示table.status仍为0而不是1。