YASH 0.1
CLI written in C
Loading...
Searching...
No Matches
jobs.h
Go to the documentation of this file.
1
9#pragma once
10
11// ============================================================================
12// Includes
13// ============================================================================
14
15#include "yash.h"
16
17// ============================================================================
18// Enums
19// ============================================================================
20
24typedef enum { JOB_RUNNING, JOB_STOPPED, JOB_DONE } JobStatus;
25
26// ============================================================================
27// Data Structures
28// ============================================================================
29
33typedef struct Job {
34 int id;
35 pid_t pgid;
40
41// ============================================================================
42// Public Functions
43// ============================================================================
44
49void jobs_init(void);
50
58int jobs_add(pid_t pgid, const char* cmdline, int is_background);
59
65void jobs_mark(pid_t pgid, JobStatus status);
66
70void jobs_print();
71
77
83
89pid_t jobs_get_pgid(int job_id);
90
95
100void jobs_print_one(int job_id);
101
107const char* jobs_get_cmdline(int job_id);
108
114void jobs_set_background(pid_t pgid, int is_bg);
void jobs_set_background(pid_t pgid, int is_bg)
Set the background of a job.
Definition jobs.c:226
const char * jobs_get_cmdline(int job_id)
Get the cmdline of a job.
Definition jobs.c:217
void jobs_reap_done_and_print(void)
Reap done jobs and print them.
Definition jobs.c:155
int jobs_add(pid_t pgid, const char *cmdline, int is_background)
Add a job to the job table.
Definition jobs.c:43
JobStatus
Represents the status of a job.
Definition jobs.h:24
void jobs_mark(pid_t pgid, JobStatus status)
Mark a job as running or stopped.
Definition jobs.c:76
struct Job Job
Represents a job.
int jobs_pick_most_recent_stopped_for_bg(void)
Pick the most recent stopped job for background.
Definition jobs.c:133
int jobs_pick_most_recent_for_fg(void)
Pick the most recent job for foreground.
Definition jobs.c:120
void jobs_print_one(int job_id)
Print a single job.
Definition jobs.c:197
pid_t jobs_get_pgid(int job_id)
Get the pgid of a job.
Definition jobs.c:145
void jobs_init(void)
Initialize the job table.
Definition jobs.c:29
void jobs_print()
Print all jobs.
Definition jobs.c:85
Represents a job.
Definition jobs.h:33
pid_t pgid
Process group ID.
Definition jobs.h:35
int is_background
Background flag: 0 = fg/stopped-in-fg; 1 = running in bg or bg'ed.
Definition jobs.h:38
int id
Job ID number.
Definition jobs.h:34
JobStatus status
Current job status.
Definition jobs.h:37
char cmdline[MAX_CMDLINE]
Command line string.
Definition jobs.h:36
Core data structures and constants.
#define MAX_CMDLINE
Maximum command line length including null terminator.
Definition yash.h:25