summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/ProcFileSystem.cpp2
-rw-r--r--Kernel/Process.cpp11
-rw-r--r--Kernel/Process.h9
-rw-r--r--Kernel/Syscall.cpp2
-rw-r--r--Kernel/Syscall.h1
-rw-r--r--LibC/unistd.cpp5
6 files changed, 22 insertions, 8 deletions
diff --git a/Kernel/ProcFileSystem.cpp b/Kernel/ProcFileSystem.cpp
index 23e05d3604..2e597514e4 100644
--- a/Kernel/ProcFileSystem.cpp
+++ b/Kernel/ProcFileSystem.cpp
@@ -269,7 +269,7 @@ ByteBuffer procfs$summary()
process->sid(),
process->uid(),
toString(process->state()),
- process->parentPID(),
+ process->ppid(),
process->timesScheduled(),
process->number_of_open_file_descriptors(),
process->tty() ? strrchr(process->tty()->ttyName().characters(), '/') + 1 : "n/a",
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index b55083ef47..e207870781 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -558,7 +558,7 @@ Process* Process::createKernelProcess(void (*e)(), String&& name)
return process;
}
-Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel ring, RetainPtr<VirtualFileSystem::Node>&& cwd, RetainPtr<VirtualFileSystem::Node>&& executable, TTY* tty, Process* fork_parent)
+Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring, RetainPtr<VirtualFileSystem::Node>&& cwd, RetainPtr<VirtualFileSystem::Node>&& executable, TTY* tty, Process* fork_parent)
: m_name(move(name))
, m_pid(next_pid++) // FIXME: RACE: This variable looks racy!
, m_uid(uid)
@@ -570,7 +570,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel
, m_cwd(move(cwd))
, m_executable(move(executable))
, m_tty(tty)
- , m_parentPID(parentPID)
+ , m_ppid(ppid)
{
if (fork_parent) {
m_sid = fork_parent->m_sid;
@@ -578,7 +578,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t parentPID, RingLevel
} else {
// FIXME: Use a ProcessHandle? Presumably we're executing *IN* the parent right now though..
InterruptDisabler disabler;
- if (auto* parent = Process::fromPID(m_parentPID)) {
+ if (auto* parent = Process::fromPID(m_ppid)) {
m_sid = parent->m_sid;
m_pgid = parent->m_pgid;
}
@@ -1315,6 +1315,11 @@ pid_t Process::sys$getpid()
return m_pid;
}
+pid_t Process::sys$getppid()
+{
+ return m_ppid;
+}
+
pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options)
{
if (wstatus)
diff --git a/Kernel/Process.h b/Kernel/Process.h
index ad8b1817ee..7558b8bfaf 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -26,7 +26,7 @@ class Process : public InlineLinkedListNode<Process> {
friend class InlineLinkedListNode<Process>;
public:
static Process* createKernelProcess(void (*entry)(), String&& name);
- static Process* create_user_process(const String& path, uid_t, gid_t, pid_t parentPID, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
+ static Process* create_user_process(const String& path, uid_t, gid_t, pid_t ppid, int& error, Vector<String>&& arguments = Vector<String>(), Vector<String>&& environment = Vector<String>(), TTY* = nullptr);
~Process();
static Vector<Process*> allProcesses();
@@ -67,7 +67,7 @@ public:
gid_t gid() const { return m_gid; }
uid_t euid() const { return m_euid; }
gid_t egid() const { return m_egid; }
- pid_t parentPID() const { return m_parentPID; }
+ pid_t ppid() const { return m_ppid; }
const FarPtr& farPtr() const { return m_farPtr; }
@@ -103,6 +103,7 @@ public:
uid_t sys$geteuid();
gid_t sys$getegid();
pid_t sys$getpid();
+ pid_t sys$getppid();
int sys$open(const char* path, int options);
int sys$close(int fd);
ssize_t sys$read(int fd, void* outbuf, size_t nread);
@@ -179,7 +180,7 @@ private:
friend class MemoryManager;
friend bool scheduleNewProcess();
- Process(String&& name, uid_t, gid_t, pid_t parentPID, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
+ Process(String&& name, uid_t, gid_t, pid_t ppid, RingLevel, RetainPtr<VirtualFileSystem::Node>&& cwd = nullptr, RetainPtr<VirtualFileSystem::Node>&& executable = nullptr, TTY* = nullptr, Process* fork_parent = nullptr);
void push_value_on_stack(dword);
@@ -233,7 +234,7 @@ private:
LinearAddress m_return_from_signal_trampoline;
- pid_t m_parentPID { 0 };
+ pid_t m_ppid { 0 };
static void notify_waiters(pid_t waitee, int exit_status, int signal);
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index db0fc9aecf..83ffab9631 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -87,6 +87,8 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2,
return current->sys$getgid();
case Syscall::SC_getpid:
return current->sys$getpid();
+ case Syscall::SC_getppid:
+ return current->sys$getppid();
case Syscall::SC_waitpid:
return current->sys$waitpid((pid_t)arg1, (int*)arg2, (int)arg3);
case Syscall::SC_mmap:
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index e91aa1f442..04cae54102 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -50,6 +50,7 @@
__ENUMERATE_SYSCALL(dup) \
__ENUMERATE_SYSCALL(dup2) \
__ENUMERATE_SYSCALL(sigaction) \
+ __ENUMERATE_SYSCALL(getppid) \
#define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function))
diff --git a/LibC/unistd.cpp b/LibC/unistd.cpp
index 058222581f..5ba180d38d 100644
--- a/LibC/unistd.cpp
+++ b/LibC/unistd.cpp
@@ -44,6 +44,11 @@ pid_t getpid()
return Syscall::invoke(Syscall::SC_getpid);
}
+pid_t getppid()
+{
+ return Syscall::invoke(Syscall::SC_getppid);
+}
+
pid_t setsid()
{
int rc = Syscall::invoke(Syscall::SC_setsid);