-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds functionality to spawn and manage processes from exec. file
- Adds fork, execvp, kill system call utils. to Mojos cLib binds - Adds utility struct. to allow spawning and managing child processes from an executable file - `run` factory method that creates process and returns "management" object - Instance methods to send signals to child process, INT, HUP, KIL Signed-off-by: Hristo I. Gueorguiev <[email protected]>
- Loading branch information
Showing
5 changed files
with
167 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ from .os import ( | |
SEEK_CUR, | ||
SEEK_END, | ||
SEEK_SET, | ||
Process, | ||
abort, | ||
getuid, | ||
listdir, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# ===----------------------------------------------------------------------=== # | ||
# Copyright (c) 2025, Modular Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License v2.0 with LLVM Exceptions: | ||
# https://llvm.org/LICENSE.txt | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ===----------------------------------------------------------------------=== # | ||
# REQUIRES: system-linux || system-darwin | ||
# RUN: %mojo %s | FileCheck %s | ||
|
||
from collections import List | ||
from os.path import exists | ||
from os import Process | ||
|
||
from testing import assert_false, assert_raises | ||
|
||
|
||
# CHECK-LABEL: TEST | ||
def test_process_run(): | ||
_ = Process.run("echo", List[String]("== TEST")) | ||
|
||
|
||
def test_process_run_missing(): | ||
missing_executable_file = "ThIsFiLeCoUlDNoTPoSsIbLlYExIsT.NoTAnExTeNsIoN" | ||
|
||
# verify that the test file does not exist before starting the test | ||
assert_false( | ||
exists(missing_executable_file), | ||
"Unexpected file '" + missing_executable_file + "' it should not exist", | ||
) | ||
|
||
# Forking appears to break asserts | ||
with assert_raises(): | ||
_ = Process.run(missing_executable_file, List[String]()) | ||
|
||
|
||
def main(): | ||
test_process_run() | ||
# TODO: How can exception being raised on missing file be asserted | ||
# test_process_run_missing() |