65 struct pgroup *pgrp = gnode->value;
67 if (pgrp->
pgid == pid)
84 for (
size_t n = 0; n < range; ++n) {
85 int pid = 1 + (
last_pid + n) % range;
143 for (
int i = 0; i <
SIG_MAX; ++i)
250 struct proc *p = node->value;
379 panic(
"init killed");
381 printk(
"kernel: reached target reboot\n");
384 panic(
"reboot not implemented\n");
394 int kill_curthread = self !=
NULL;
471 if (kill_curthread) {
473 panic(
"How did we get here?");
608 if (!pgrp)
goto e_nomem;
613 pgrp->
procs = queue_new();
614 if (!pgrp->
procs)
goto e_nomem;
622 if (!node)
goto e_nomem;
677 struct pgroup *pg = node->value;
695 if (!(pgrp->
procs = queue_new())) {
static void arch_interrupts_disable(void)
Masks IRQs.
void arch_cur_thread_kill(void)
Ends the current thread.
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
int file_put(struct file *file)
Drops a reference to an open file.
void thread_files_release(struct thread *thread)
Lets go of the open files a thread's system call held, when the call returns or the thread is killed.
void tty_hangup(struct tty *tty)
Hangs up a controlling terminal, when its session ends (its leader exited) or the terminal goes away:...
#define MALLOC_DEFINE(type, _name, _desc)
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
void kfree(void *)
Frees an object that kmalloc() gave.
void pmap_decref(struct pmap *pmap)
Drops a reference to an address space's page tables, freeing them with the last one.
struct pmap * pmap_create(void)
Makes the page tables of a new address space: an empty user half, and the kernel's half,...
int printk(const char *fmt,...)
Writes a kernel message, to the message buffer and the consoles.
int proc_fd_get(struct proc *proc)
Reserves the lowest free descriptor of a process, while a system call sets it up: no other thread tak...
void proc_threads_exec(struct proc *proc)
Ends every thread of a process but the current one, for execve() (POSIX: they run in the program that...
int proc_fd_close(struct proc *proc, int fd)
Closes a descriptor: it is free again, and its reference to the open file is dropped.
void proc_pid_free(int pid)
Frees a process ID.
int proc_reap(struct proc *proc)
Frees a zombie, once its parent waited for it (or doesn't wait for its children).
int proc_init(struct proc *proc)
Gives a new process (init) its ID and its descriptor table.
int proc_threads_end(struct proc *proc, struct thread *keep, int exiting)
Ends the threads of a process, but one.
struct file * proc_fd_file(struct proc *proc, int fd)
Finds the open file a descriptor refers to.
pid_t proc_pid_alloc(void)
Allocates a process ID, from 1 (init's) on.
void proc_fd_release(struct proc *proc, int fd)
Frees a reserved descriptor that wasn't set up after all.
int pgrp_orphaned(struct pgroup *pgrp, struct proc *gone)
Says whether a process group is orphaned (POSIX): none of its members has a parent in another group o...
int proc_new(struct proc **ref)
Makes a new process structure, with one thread and an empty address space, on the list of every proce...
struct proc * proc_pid_find(pid_t pid)
Finds a process by its ID.
int session_new(struct proc *proc)
Makes a new session, with a new process group, both led by a process and with its ID,...
void proc_fd_install(struct proc *proc, int fd, struct file *file, int flags)
Makes a reserved descriptor refer to an open file.
int proc_setpgid(struct proc *proc, pid_t pgid)
Moves a process into a process group of its session, as setpgid() does.
void proc_kill(struct proc *proc)
Ends a process: its threads end, its descriptors are closed, its memory is freed, its children go to ...
void pgrp_release(struct pgroup *pgrp)
Frees a process group if no process is left in it, and its session if that was the session's last gro...
void arch_reboot(void)
Restarts the machine.
void sched_timer_cancel(struct thread *thread)
Takes a thread off the list of threads waiting with a deadline, when it no longer waits (it was woken...
void sched_alarm(struct proc *proc, uint64_t value, uint64_t interval, uint64_t *old_value, uint64_t *old_interval)
Sets a process's real time timer, which setitimer() and alarm() use: the process gets SIGALRM once va...
struct cpu * sched_thread_cpu(struct thread *thread)
Finds the CPU that is running a thread, if it's another CPU than this one.
void sched_thread_kick(struct thread *thread)
Makes a thread that runs on another CPU enter the kernel now, rather than at its next tick: a signal ...
int signal_proc_send(struct proc *proc, int signal)
Sends a signal to a process.
int signal_pgrp_send(struct pgroup *pg, int signal)
Sends a signal to every process of a process group.
A bitmap: its blocks, and its last bit's index.
A file descriptor: the open file it refers to (fs/file.c, shared with the descriptors that dup() and ...
An open file (POSIX's "open file description", fs/file.c).
A process group: the processes of a job.
struct proc * leader
its leader, the process whose PID is its ID
struct queue * procs
its processes
struct session * session
its session
struct qnode * session_node
its node on its session's list
An address space's page tables, on x86.
pid_t pid
the process's ID
struct proc * parent
its parent
struct aquila_sigaction sigaction[SIG_MAX+1]
its signal actions
uint64_t utime
its CPU time in user mode and in the kernel (ns), and that of the children it waited for
struct waitq wait_queue
a parent waiting for a child (waitpid()) sleeps here
struct vm_space vm_space
its address space
struct waitq thread_join
threads waiting in thread_join() sleep here
int exit
its exit status (PROC_EXIT())
struct vnode * cwd
its current directory (a reference), or NULL for the root
int stopped
the signal that stopped it, or 0; and what waitpid() has to report (WAIT_*)
int running
whether it's running
struct fd * fds
its file descriptors (FDS_COUNT of them)
char * name
its name: the program it runs
struct queue threads
its threads
sigset_t sig_pending
its pending signals, a bit (1 << sig) each: a signal sent again while it's pending is delivered once ...
struct pgroup * pgrp
its process group, and its node on the group's list
int zombie
proc_kill() is done with it, so it can be reaped (that isn't as soon as it stops running: closing its...
A queue's node, holding one entry.
A session: its process groups, and its controlling terminal.
struct queue * pgps
its process groups
struct tty * ctty
its controlling terminal, or NULL
struct proc * leader
its leader, the process that made it
pid_t sid
the session's ID
struct list_node run_link
it's on the ready list (sched.c) while it's ready to run, or on the wait queue it sleeps on (waitq); ...
int killed
it was killed (proc_threads_end()) while it ran on another CPU: it frees itself there,...
struct proc * owner
its process
struct pgroup * fg
the foreground process group, or NULL
struct session * session
the session it is the controlling terminal of, or NULL
An address space: its mappings, and its page tables.
struct pmap * pmap
its page tables (the architecture's)
static void pgrp_orphaned_hangup(struct pgroup *pgrp, struct proc *gone)
Sends SIGHUP and SIGCONT to a process group that gone leaving makes orphaned, if one of its members i...
static int pgrp_other_same_session(struct proc *p, struct proc *q)
Returns whether p's process group is another group of the same session as q's.
static int pid_is_group(int pid)
Returns whether a process group or a session has pid as its ID.
struct bitmap * pid_bitmap
static void proc_zombie_notify(struct proc *proc)
Tells a zombie's parent that it ended: its wait() wakes up and it gets SIGCHLD.
int thread_kill(struct thread *thread)
Releases what a thread holds (its poll() registrations, its CPU state and kernel stack) and makes it ...
int thread_new(struct proc *proc, struct thread **rthread)
Makes a new thread in a process.
struct vm_space kvm_space
void vm_space_destroy(struct vm_space *vm_space)
Removes all the mappings of an address space: its entries are released and freed, and its page tables...
void waitq_wakeup(struct waitq *waitq)
Wakes up every thread sleeping on a wait queue, and every thread polling it.
void waitq_sleep_unint(struct waitq *waitq)
Puts the current thread to sleep on a wait queue until it is woken up, whatever signals come meanwhil...