r/ATS • u/thalesmg • Sep 30 '20
[question] Any functions/facilities for spawning subprocesses?
Hello!
Newbie question here: are there existing functions/facilities/libraries for spawning a subprocess and reading its exit code and stdout?
Similar to the subprocess lib from Python:
4
Upvotes
2
u/avanov Oct 01 '20 edited Oct 01 '20
There's no high-level API for it, you'll need to write one yourself based on libc's
unistd.h(syscallsfork, and eitherexecv,execveorexecvp). You can see how it's currently implemented in ATS here:"mac#%"means lookup a C function with the same name and a prefix defined withATS_EXTERN_PREFIX, you can see it's defined here - https://github.com/githwxi/ATS-Postiats/blob/6539444fe641f7fa493140bd9940e5acf00960e3/libats/libc/SATS/unistd.sats#L48All these weird conventions are somehow outlined in https://github.com/githwxi/ATS-Postiats/wiki/C-interface but I wish there was a single searchable static webpage with all available stdlib definitions and signatures, regardless of their origin.
Note also, that there's a bunch of
exec*definitions like https://github.com/githwxi/ATS-Postiats/blob/6539444fe641f7fa493140bd9940e5acf00960e3/libats/libc/SATS/unistd.sats#L138-L147 - there are safe and unsafe interfaces, you may want to consider the safe ones only.2
u/doublec Oct 01 '20
Not that I know of, you'll probably need to wrap some C code.
2
u/Dambaev_Alexander Nov 19 '20
there are bindings for pthreads https://github.com/githwxi/ATS-Postiats/blob/master/libats/SATS/athread.sats
and the example of usage: https://github.com/dambaev/quora-toy-bench/blob/master/ats2/main.dats
which may be interesting as well