int handle_parallel_builtins(char **command, Node **paused_list, Node **cpidlist, char mode) { if (strcmp(command[0], "jobs") != 0 && strcmp(command[0], "pause") != 0 && strcmp(command[0], "resume") != 0) { return 0; } else if (mode != 'p') { printf("This command is only supported in parallel mode.\n"); return 0; } char return_int = 0; if (strcmp(command[0], "jobs") == 0 && command[1] == NULL) { return_int = 1; Node *tempcpidlist = *cpidlist; char *status = "Running"; while (tempcpidlist != NULL) { if (list_matches(tempcpidlist->data, *paused_list)) { status = "Paused"; } printf("Process %s (%s): %s \n", tempcpidlist->data, tempcpidlist->additional_data, status); tempcpidlist = tempcpidlist->next; } } else if(strcmp(command[0], "pause") == 0 && command[1] != NULL) { if (valid_int(command[1])) { return_int = 1; pid_t pid = atoi(command[1]); if (kill(pid, SIGSTOP) == 0) { list_append(command[1], "", paused_list); } else { fprintf(stderr, "pause failed: %s\n", strerror(errno)); } } } else if(strcmp(command[0], "resume") == 0 && command[1] != NULL) { if (valid_int(command[1] )) { return_int = 1; pid_t pid = atoi(command[1]); if (!list_matches(command[1], *paused_list)) { printf("Either that's not a process, or you're trying to continue a process that's not paused!\n"); } else { if (kill(pid, SIGCONT) == 0) { list_delete(command[1], paused_list); } else { fprintf(stderr, "resume failed: %s\n", strerror(errno)); } } } } return return_int; }
void parse(t_env *env) { t_parser p; int rd; p.is_start = 0; p.is_end = 0; p.link_part = 0; while ((rd = get_next_line(0, &(p.line))) == 1) { if (p.line[0] != '#' || (p.line[1] && p.line[1] == '#')) { if (env->ants == -1) { if (valid_int(p.line)) env->ants = ft_atoi(p.line); else return ; } else if (!parse_line(env, &p)) return ; } add_file_line(env, p.line); } if (rd == -1) error_quit("Error while reading stdin"); }
bool ok_shelf(char *input) { return strlen(input) == 3 && isalpha(input[0]) && valid_int(input+1); }