job control: sessions and process groups

This commit is contained in:
Matheus
2024-05-01 21:42:38 -03:00
parent 1f848fe596
commit 05049a091f
13 changed files with 484 additions and 18 deletions
+17
View File
@@ -0,0 +1,17 @@
#ifndef _JOBCTL_H
#define _JOBCTL_H
#include <kernel/scheduler.h>
int jobctl_newsession(proc_t *proc);
int jobctl_newgroup(proc_t *proc);
int jobctl_changegroup(proc_t *proc, proc_t *group);
void jobctl_detach(proc_t *);
void jobctl_addproc(proc_t *parent, proc_t *proc);
void jobctl_procremove(proc_t *proc);
pid_t jobctl_getpgid(proc_t *proc);
pid_t jobctl_getsid(proc_t *proc);
void jobctl_setctty(proc_t *proc, void *ctty);
void *jobctl_getctty(proc_t *proc);
#endif
+23
View File
@@ -74,6 +74,29 @@ typedef struct proc_t {
semaphore_t waitsem;
spinlock_t exiting;
bool nomorethreads;
spinlock_t jobctllock;
struct {
// NULL if this process is leader
struct proc_t *leader;
// these are only applicable if the process is leader
struct proc_t *foreground; // process group leader, NULL if self
void *controllingtty;
int processcount; // refcount
} session;
struct {
// NULL if this process is leader
struct proc_t *leader;
// linked list
struct proc_t *nextmember;
struct proc_t *previousmember;
// these are only applicable if the process is leader
spinlock_t lock; // protects the linked list
int processcount; // refcount
} pgrp;
} proc_t;
#include <arch/cpu.h>
+2
View File
@@ -5,6 +5,7 @@
#include <termios.h>
#include <kernel/poll.h>
#include <ringbuffer.h>
#include <kernel/vfs.h>
#define DEVICE_BUFFER_SIZE 512
#define READ_BUFFER_SIZE 4096
@@ -23,6 +24,7 @@ typedef struct {
ttydevicewritefn_t writetodevice;
int minor;
winsize_t winsize;
vnode_t *mastervnode;
} tty_t;
void tty_init();
+1
View File
@@ -55,6 +55,7 @@ typedef struct vfs_t {
#define V_FFLAGS_NONBLOCKING 4
#define V_FFLAGS_SHARED 8
#define V_FFLAGS_EXEC 16
#define V_FFLAGS_NOCTTY 32
typedef struct vnode_t {
struct vops_t *ops;