Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Posix.ProcEnv.getpid #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/rts/src/OS/Unix/unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,12 @@ static mlval unix_kill(mlval arg)
return MLUNIT;
}

static mlval unix_getpid(mlval arg)
{
pid_t pid = getpid ();
return MLINT(pid);
}

/*
* OS.Process.terminate: Word32.word -> 'a
*/
Expand Down Expand Up @@ -1693,6 +1699,7 @@ extern void unix_init(void)
env_function("system os unix getpwnam", unix_getpwnam);
env_function("system os unix password_file", unix_password_file);
env_function("system os unix kill", unix_kill);
env_function("system os unix getpid", unix_getpid);

env_function("system os unix pipe", unix_pipe);

Expand Down
12 changes: 12 additions & 0 deletions src/unix/_unixos.sml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ struct
val close : FileSys.file_desc -> unit = MLWorks.Internal.IO.close
end

structure Process = struct
datatype pid = PID of int
fun pidToWord (PID id) = SysWord.fromInt id
fun wordToPid w = PID (SysWord.toInt w)
end

structure ProcEnv = struct
type pid = Process.pid
val getpid' : unit -> int = env "system os unix getpid"
fun getpid () = Process.PID (getpid' ())
end

val can_input : FileSys.file_desc -> int = MLWorks.Internal.IO.can_input

val set_block_mode : FileSys.file_desc * bool -> unit =
Expand Down
2 changes: 2 additions & 0 deletions src/unix/platform_specific_exports.sml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

require "unix";
require "__unix";
require "__unixos";

signature UNIX = UNIX;
structure Unix = Unix;
structure Posix = UnixOS_;
11 changes: 10 additions & 1 deletion src/unix/unixos.sml
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,20 @@ signature UNIXOS =

end


structure IO : sig
val close : FileSys.file_desc -> unit
end

structure Process : sig
eqtype pid
val pidToWord : pid -> SysWord.word
val wordToPid : SysWord.word -> pid
end

structure ProcEnv : sig
eqtype pid
val getpid : unit -> pid
end

val can_input : FileSys.file_desc -> int
val set_block_mode : FileSys.file_desc * bool -> unit
Expand Down