I tried for something like this:
import system, os, osproc, threadpool
import locks
var
thr1: Thread[string]
thr2: Thread[string]
L: Lock
proc threadExec(p: string) {.thread.} =
discard execProcess(p)
proc threadQuit {.thread.} =
os.sleep(1000)
quit(1)
initLock(L)
createThread(thr1, threadExec, (paramStr(1)))
createThread(thr2, threadQuit)
joinThreads(thr1,thr2)
quit(1)
To immediately stop parent process after child process execution but, without responce from childside. So is' there an example of how to implement it correctly, not like a thread, just mb it's already implemented option.
import system,rdstdin,strutils,sequtils
proc execvp*(file:cstring,args:cstringArray):cint{.header: "<unistd.h>", importc.}
proc fork*():cint{.header: "<unistd.h>", importc.}
let input = readLinefromstdin("enter command:>").split(' ').allocCStringArray()#does not do quote handling!
let pid = fork()
if pid==0:
echo("child calling: " & $cStringArraytoSeq(input))
let ret = execvp(input[0],input)
assert(false)#unreachable
deallocCStringArray(input)
echo ("parent process quitting")