Skip to content

Commit fc05b1b

Browse files
committed
added os.getpid()
1 parent 36be62f commit fc05b1b

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

main

4.2 KB
Binary file not shown.

os/os.module.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func init() {
1818
py.MustNewMethod("getcwd", getCwd, 0, "Get the current working directory"),
1919
py.MustNewMethod("chdir", chdir, 0, "Change the current working directory"),
2020
py.MustNewMethod("getenv", getenv, 0, "Return the value of the environment variable key if it exists, or default if it doesn’t. key, default and the result are str."),
21+
py.MustNewMethod("getpid", getpid, 0, "Return the current process id."),
2122
}
2223

2324
globals := py.StringDict{
@@ -111,3 +112,8 @@ func getenv(self py.Object, args py.Tuple) (py.Object, error) {
111112
return res, nil
112113
}
113114
}
115+
116+
// get the current process' pid
117+
func getpid(self py.Object, args py.Tuple) (py.Object, error) {
118+
return py.Int(os.Getpid()), nil
119+
}

os/os.test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
print("cwd() after chdir():", os.getcwd()) # should print $HOME dir
1212
print()
1313
print("getenv(\"HOME\"):", os.getenv("HOME")) # should print $HOME dir
14+
print()
15+
print("getpid():", os.getpid()) # prints the process id

0 commit comments

Comments
 (0)