- Implemented execp*.
[planlOS.git] / system / include / ke / process.h
blob814d20577e93631eed16e4e1ded47afde57662d7
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 /**
22 * \file process.h
23 * Process management functions
26 #ifndef KE_PROCESS_H_INCLUDED
27 #define KE_PROCESS_H_INCLUDED
29 #include <stdint.h>
30 #include <planlos/signals.h>
31 #include "mm/memory.h"
32 #include "fs/fs.h"
34 /**
35 * Process information
37 typedef struct KeProcess
39 /**
40 * Address space of the process
42 MmAddressSpace memory;
43 /**
44 * Process ID
46 uint32_t pid;
47 /**
48 * Array of threads in the process.
50 struct KeThread **threads;
51 /**
52 * Number of threads
54 uint32_t threadcount;
55 /**
56 * Process lock. Has to be locked whenever the process is modified.
58 KeSpinlock lock;
60 /**
61 * If this is set to 1, the process is a zombie process (was closed, but not
62 * waited for).
64 int zombie;
66 /**
67 * Array containing the open file handles. Entries can be 0 if the file was
68 * closed.
70 FsFileHandle **fd;
71 /**
72 * Number of entries in the fd array.
74 uint32_t fdcount;
75 /**
76 * Current working directory.
78 char *cwd;
80 /**
81 * Signal handlers for the current process.
83 uintptr_t signal_handlers[NSIG];
85 struct KeThread *waitthread;
86 } KeProcess;
88 /**
89 * Initialitzes the process system.
91 int keInitProcessManager(void);
93 /**
94 * Creates a new process, with an empty address space and no threads attached.
96 KeProcess *keCreateProcess(void);
97 /**
98 * Stops all threads belonging to a process and stops the process (makes it a
99 * zombie process).
101 int keTerminateProcess(KeProcess *process);
103 * Stops all threads belonging to a process and completely destroys the process.
105 int keDestroyProcess(KeProcess *process);
107 * Clears the address space of the process and stops all threads in it but the
108 * current thread.
110 int keClearProcess(KeProcess *process, struct KeThread *current);
113 * Returns the process with the given ID.
115 KeProcess *keGetProcess(uint32_t pid);
118 * Sends a signal to the process.
120 void keSendSignal(KeProcess *process, struct KeThread *thread, int signal);
122 #endif