167 lines
4.7 KiB
HTML
167 lines
4.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="description" content="MontaukOS manual page: spawn(2) - create and wait for processes">
|
|
<title>spawn(2) - MontaukOS Manual</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&display=swap" rel="stylesheet">
|
|
<style>
|
|
body {
|
|
font-family: 'Open Sans', Arial, sans-serif;
|
|
max-width: 960px;
|
|
margin: 0 auto;
|
|
padding: 1em;
|
|
line-height: 1.5;
|
|
display: flex;
|
|
gap: 2em;
|
|
}
|
|
p { margin: 0 0 0.5em; }
|
|
h2 { margin: 0.5em 0; }
|
|
.sidebar {
|
|
width: 160px;
|
|
flex-shrink: 0;
|
|
}
|
|
.sidebar ul {
|
|
list-style: none;
|
|
padding: 0;
|
|
}
|
|
.sidebar li {
|
|
margin: 0.5em 0;
|
|
}
|
|
.sidebar a {
|
|
color: #0066CC;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
}
|
|
.sidebar a:hover {
|
|
color: #004499;
|
|
text-decoration: underline;
|
|
}
|
|
.sidebar .current {
|
|
color: #004499;
|
|
}
|
|
.sidebar hr {
|
|
border: none;
|
|
border-top: 1px solid #999;
|
|
margin: 0.75em 0;
|
|
}
|
|
.main {
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
a { color: #0000EE; }
|
|
a:visited { color: #0066CC; }
|
|
hr { border-style: solid; border-width: 1px 0 0 0; border-color: #999; }
|
|
pre { background: #f0f0f0; padding: 0.5em; overflow-x: auto; }
|
|
code { background: #f0f0f0; padding: 0 0.15em; }
|
|
pre code { padding: 0; }
|
|
.center { text-align: center; }
|
|
.box {
|
|
border: 1px solid #999;
|
|
padding: 0.5em;
|
|
margin: 0.5em 0;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="sidebar">
|
|
<ul>
|
|
<li><a href="../../index.html">Home</a></li>
|
|
<li><a href="../index.html">Documentation</a></li>
|
|
</ul>
|
|
<hr>
|
|
<ul>
|
|
<li><a href="index.html" class="current">Man Pages</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="main">
|
|
<div class="center">
|
|
<h1>spawn(2)</h1>
|
|
</div>
|
|
|
|
<hr>
|
|
|
|
<pre><code><strong>NAME</strong>
|
|
spawn, waitpid - create and wait for processes
|
|
|
|
<strong>SYNOPSIS</strong>
|
|
<strong> int montauk::spawn(const char* path, const char* args = nullptr);</strong>
|
|
<strong> void montauk::waitpid(int pid);</strong>
|
|
<strong> int montauk::getargs(char* buf, uint64_t maxLen);</strong>
|
|
|
|
<strong>DESCRIPTION</strong>
|
|
|
|
<strong>spawn</strong>
|
|
Loads the ELF64 binary at the given VFS path and creates a new
|
|
process. The path must include the drive prefix, for example:
|
|
|
|
int pid = montauk::spawn("0:/os/hello.elf");
|
|
|
|
An optional second argument passes a string to the child:
|
|
|
|
int pid = montauk::spawn("0:/os/man.elf", "intro");
|
|
|
|
The new process gets its own PML4 page table, a 32 KiB stack
|
|
(at 0x7FFFFF7000-0x7FFFFFF000), and begins executing at the
|
|
ELF entry point (_start).
|
|
|
|
Returns the new process's PID on success, or -1 on failure.
|
|
Failure occurs when there are no free process slots (max 256),
|
|
the file cannot be found, or the ELF is invalid.
|
|
|
|
<strong>waitpid</strong>
|
|
Blocks the calling process until the process with the given PID
|
|
has exited. Internally, this yields the CPU in a loop:
|
|
|
|
montauk::waitpid(pid);
|
|
|
|
This is how the shell implements foreground process execution --
|
|
it spawns a child and waits for it to complete before showing
|
|
the next prompt.
|
|
|
|
<strong>EXAMPLES</strong>
|
|
Spawn a program and wait for it:
|
|
|
|
int pid = montauk::spawn("0:/os/hello.elf");
|
|
if (pid < 0) {
|
|
montauk::print("spawn failed\n");
|
|
} else {
|
|
montauk::waitpid(pid);
|
|
montauk::print("child exited\n");
|
|
}
|
|
|
|
<strong>getargs</strong>
|
|
Copies the argument string into buf (up to maxLen bytes, always
|
|
null-terminated). Returns the number of characters copied, or
|
|
-1 on error.
|
|
|
|
char args[256];
|
|
montauk::getargs(args, sizeof(args));
|
|
|
|
The argument string is set by the parent when calling spawn().
|
|
If no arguments were provided, the buffer will be empty.
|
|
|
|
<strong>NOTES</strong>
|
|
The _start() entry point receives no argc/argv. Use getargs()
|
|
to retrieve the argument string passed by the parent process.
|
|
|
|
Process exit codes are not yet collected by waitpid.
|
|
|
|
<strong>SEE ALSO</strong>
|
|
syscalls(2), file(2)</code></pre>
|
|
|
|
<hr>
|
|
|
|
<div class="center">
|
|
<a href="../index.html">Back to Documentation Index</a>
|
|
</div>
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|