job control: kill/cont process groups

This commit is contained in:
K. Lange 2018-10-26 23:19:46 +09:00
parent 5aaaf9f8ce
commit 51df8004dd
5 changed files with 40 additions and 3 deletions

View File

@ -1882,7 +1882,7 @@ uint32_t shell_cmd_fg(int argc, char * argv[]) {
return 0;
}
if (kill(pid, SIGCONT) < 0) {
if (kill(-pid, SIGCONT) < 0) {
fprintf(stderr, "no current job / bad pid\n");
hashmap_remove(job_hash, (void*)pid);
return 1;

View File

@ -224,6 +224,7 @@ typedef struct {
extern void handle_signal(process_t *, signal_t *);
extern int send_signal(pid_t process, uint32_t signal, int force);
extern int group_send_signal(int group, uint32_t signal, int force_root);
#define USER_STACK_BOTTOM 0xAFF00000
#define USER_STACK_TOP 0xB0000000

View File

@ -139,7 +139,7 @@ void tty_input_process(pty_t * pty, uint8_t c) {
}
clear_input_buffer(pty);
if (pty->fg_proc) {
send_signal(pty->fg_proc, sig, 1);
group_send_signal(pty->fg_proc, sig, 1);
}
return;
}

View File

@ -267,3 +267,35 @@ int send_signal(pid_t process, uint32_t signal, int force_root) {
return 0;
}
int group_send_signal(int group, uint32_t signal, int force_root) {
int kill_self = 0;
int killed_something = 0;
debug_print(WARNING, "killing group %d", group);
foreach(node, process_list) {
process_t * proc = node->value;
debug_print(WARNING, "examining %d %d %d", proc->id, proc->job, proc->group);
if (proc->group == proc->id && proc->job == group) {
/* Only thread group leaders */
debug_print(WARNING, "killing %d", proc->group);
if (proc->group == current_process->group) {
kill_self = 1;
} else {
if (send_signal(proc->group, signal, force_root) == 0) {
killed_something = 1;
}
}
}
}
if (kill_self) {
if (send_signal(current_process->group, signal, force_root) == 0) {
killed_something = 1;
}
}
return !!killed_something;
}

View File

@ -780,7 +780,11 @@ static int sys_shm_release(char * path) {
}
static int sys_kill(pid_t process, uint32_t signal) {
return send_signal(process, signal, 0);
if (process < -1) {
return group_send_signal(-process, signal, 0);
} else {
return send_signal(process, signal, 0);
}
}
static int sys_gettimeofday(struct timeval * tv, void * tz) {