1 Star 2 Fork 0

黄圳伟 / wish

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jobs.h 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
黄圳伟 提交于 2021-07-21 15:37 . 源代码
//
// Created by zavier on 2021/7/18.
//
#ifndef WISH_JOBS_H
#define WISH_JOBS_H
#include <unistd.h>
#include <iostream>
#include <string>
#include <vector>
#include <list>
class Jobs {
public:
enum JobState{
UNDEFINE, //未定义
BACKGROUND,//后台任务
FOREGROUND, //前台任务
STOP //暂停任务
};
struct Job{
pid_t pid; /* job PID */
int jid; /* job ID [1, 2, ...] */
int state; /* UNDEF, BG, FG, or ST */
std::string cmd; /* command line */
};
Jobs(){
nextJid=1;
jobs.resize(JOBSIZE);
for(auto &job:jobs){
clearJob(job);
}
}
bool addJob(pid_t pid,int state,const std::string &cmd);
bool deleteByPid(pid_t pid);
bool deleteByJid(int jid);
Job* getJobBypid(pid_t pid);
Job* getJobByJid(int jid);
Job* getForegroundJob();
pid_t getForegroundJobPid();
void printJobs();
size_t size();
int maxJid();
friend std::ostream &operator<<(std::ostream &os,Jobs);
private:
static constexpr int JOBSIZE=100;
int nextJid;
size_t currentJobs;
std::vector<Job> jobs;
void clearJob(Job &job);
};
#endif //WISH_JOBS_H
1
https://gitee.com/huang_zhenwei/wish.git
git@gitee.com:huang_zhenwei/wish.git
huang_zhenwei
wish
wish
master

搜索帮助