Skip to content

Instantly share code, notes, and snippets.

@tanmaykm
Created April 15, 2014 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanmaykm/10726511 to your computer and use it in GitHub Desktop.
Save tanmaykm/10726511 to your computer and use it in GitHub Desktop.
Try creating daemon process in Julia
function daemon()
cpid = ccall(:fork, Cint, ())
if cpid != 0
exit()
else
ccall(:setsid, Cint, ())
cpid = ccall(:fork, Cint, ())
if cpid != 0
exit()
else
for idx in 1:1024
ccall(:close, Int32, (Int32,), idx)
end
fd = ccall(:open, Int32, (Ptr{Uint8}, Int32), "/dev/null", Base.FS.JL_O_RDWR)
ccall(:dup2, Int32, (Int32,Int32), fd, 1)
ccall(:dup2, Int32, (Int32,Int32), fd, 2)
while(true)
# using sleep kills the process???
# sleep(2)
f = open("/tmp/forkchk.txt", "w")
println(f, time())
close(f)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment