LINUX 中 SIGCONT 和 waitpid() 的问题
ISSUES with SIGCONT and waitpid() in LINUX
我会尽量保持简单。我目前正在为 LINUX 复制 shell。我使用链表结构"job_list"来存储所有后台进程。如果后台进程终止,则将其从列表中删除。如果后台进程被挂起,其在列表中的状态将从 BACKGROUND 更改为 STOPPED。如果进程被重新唤醒(通过 SIGCONT 信号),那么想法是列表中的进程状态应该变回 BACKGROUND。
我的问题如下:当我向进程发送 SIGSTOP 信号时,执行部分 //1 并且它的状态更改已成功注册到列表中。但是,当我使用 SIGCONT 信号重新唤醒同一个进程时,WIFCONTINUED(status) 将 return false,但 WIFEXITED(status) 将始终 return true。因此,执行//3 部分并将进程从列表中删除。
有什么问题吗?提前致谢。
void sigchld_handler (){
block_SIGCHLD();
job *item;
int l_size = list_size(job_list);
int i, new_pid, pid_wait, status, info;
enum status status_res;
for (i = 1; i <= l_size; i++){
item = get_item_bypos(job_list, i);
new_pid = item->pgid;
pid_wait = waitpid(new_pid, &status, WUNTRACED | WNOHANG);
if (WIFSTOPPED(status)){
//1
printf("****SUSPENDED\n");
item->state = STOPPED;
}else if (WIFCONTINUED(status)){
//2
printf("****CONTINUED\n");
item->state = BACKGROUND;
}else if (WIFEXITED(status)){
//3
printf("****EXITED\n");
l_size--;
i--;
delete_job(job_list, item);
}
}
print_job_list(job_list);
unblock_SIGCHLD();
}
您在调用 waitpid
时似乎缺少 WCONTINUED
值。
来自waitpid
specification:
pid_t waitpid(pid_t pid, int *stat_loc, int options);
The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the header:
WCONTINUED
The waitpid() function shall report the status of any continued child process specified by pid whose status has not been reported since it continued from a job control stop.
我会尽量保持简单。我目前正在为 LINUX 复制 shell。我使用链表结构"job_list"来存储所有后台进程。如果后台进程终止,则将其从列表中删除。如果后台进程被挂起,其在列表中的状态将从 BACKGROUND 更改为 STOPPED。如果进程被重新唤醒(通过 SIGCONT 信号),那么想法是列表中的进程状态应该变回 BACKGROUND。
我的问题如下:当我向进程发送 SIGSTOP 信号时,执行部分 //1 并且它的状态更改已成功注册到列表中。但是,当我使用 SIGCONT 信号重新唤醒同一个进程时,WIFCONTINUED(status) 将 return false,但 WIFEXITED(status) 将始终 return true。因此,执行//3 部分并将进程从列表中删除。
有什么问题吗?提前致谢。
void sigchld_handler (){
block_SIGCHLD();
job *item;
int l_size = list_size(job_list);
int i, new_pid, pid_wait, status, info;
enum status status_res;
for (i = 1; i <= l_size; i++){
item = get_item_bypos(job_list, i);
new_pid = item->pgid;
pid_wait = waitpid(new_pid, &status, WUNTRACED | WNOHANG);
if (WIFSTOPPED(status)){
//1
printf("****SUSPENDED\n");
item->state = STOPPED;
}else if (WIFCONTINUED(status)){
//2
printf("****CONTINUED\n");
item->state = BACKGROUND;
}else if (WIFEXITED(status)){
//3
printf("****EXITED\n");
l_size--;
i--;
delete_job(job_list, item);
}
}
print_job_list(job_list);
unblock_SIGCHLD();
}
您在调用 waitpid
时似乎缺少 WCONTINUED
值。
来自waitpid
specification:
pid_t waitpid(pid_t pid, int *stat_loc, int options);
The options argument is constructed from the bitwise-inclusive OR of zero or more of the following flags, defined in the header:
WCONTINUED
The waitpid() function shall report the status of any continued child process specified by pid whose status has not been reported since it continued from a job control stop.