我目前潜入创建一个backgrounding工作C用&.我需要实现非阻塞waitpid才能使其正常工作.我知道.此外,如果&在命令行末尾输入,我已经抓住了这个条件.我只是不确定如何准确地将进程作为后台作业发送,并将其实现为执行,而另一个提示是提示下一个命令.
任何事情都会有所帮助,谢谢.
struct bgprocess{
int pid;
struct bgprocess * next;
struct bgprocess * prev;
};
struct bgprocess * bgprocess1;
bgprocess1 = malloc(sizeof(struct bgprocess));
bgprocess1->prev = NULL;
bgprocess1->next = NULL;
bgprocess1->pid = NULL;
struct bgprocess * current;
current = bgprocess1;
do{
int bgreturn = 0;
while (current != NULL){
if (waitpid(current->pid, &bgreturn, WNOHANG)){
printf("Child exited");
current->prev->next = current->next;
current->next->prev = current->prev;
current->prev = NULL;
current->next = NULL;
free(current);
}
current = current->next;
} …Run Code Online (Sandbox Code Playgroud)