本文整理汇总了C++中parser_t::job_get_from_pid方法的典型用法代码示例。如果您正苦于以下问题:C++ parser_t::job_get_from_pid方法的具体用法?C++ parser_t::job_get_from_pid怎么用?C++ parser_t::job_get_from_pid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parser_t
的用法示例。
在下文中一共展示了parser_t::job_get_from_pid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: builtin_disown
/// Builtin for removing jobs from the job list.
int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
help_only_cmd_opts_t opts;
int optind;
int retval = parse_help_only_cmd_opts(opts, &optind, argc, argv, parser, streams);
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd, streams.out);
return STATUS_CMD_OK;
}
if (argv[1] == 0) {
// Select last constructed job (ie first job in the job queue) that is possible to disown.
// Stopped jobs can be disowned (they will be continued).
// Foreground jobs can be disowned.
// Even jobs that aren't under job control can be disowned!
job_t *job = nullptr;
for (const auto &j : jobs()) {
if (j->is_constructed() && (!j->is_completed())) {
job = j.get();
break;
}
}
if (job) {
retval = disown_job(cmd, parser, streams, job);
} else {
streams.err.append_format(_(L"%ls: There are no suitable jobs\n"), cmd);
retval = STATUS_CMD_ERROR;
}
} else {
std::set<job_t *> jobs;
// If one argument is not a valid pid (i.e. integer >= 0), fail without disowning anything,
// but still print errors for all of them.
// Non-existent jobs aren't an error, but information about them is useful.
// Multiple PIDs may refer to the same job; include the job only once by using a set.
for (int i = 1; argv[i]; i++) {
int pid = fish_wcstoi(argv[i]);
if (errno || pid < 0) {
streams.err.append_format(_(L"%ls: '%ls' is not a valid job specifier\n"), cmd,
argv[i]);
retval = STATUS_INVALID_ARGS;
} else {
if (job_t *j = parser.job_get_from_pid(pid)) {
jobs.insert(j);
} else {
streams.err.append_format(_(L"%ls: Could not find job '%d'\n"), cmd, pid);
}
}
}
if (retval != STATUS_CMD_OK) {
return retval;
}
// Disown all target jobs
for (const auto &j : jobs) {
retval |= disown_job(cmd, parser, streams, j);
}
}
return retval;
}