Skip to content

@headius /gist:579505
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
~/projects/jruby ➔ jruby -rreal_unix -e 'trap("INT") { puts :there; exit }; puts :here; select(nil, nil, nil, nil)'
here
^Cthere
~/projects/jruby ➔ jruby -rreal_unix -e 'puts $$; exec "echo $$"'
461
461
~/projects/jruby ➔ cat real_unix.rb
require 'ffi'
module RealUnix
extend FFI::Library
ffi_lib 'c'
attach_function :execv, [ :string, :buffer_in ], :int
attach_function :exit, [ :int ], :void
def self.exec(*args)
args.unshift "/bin/sh", "-c"
cmd = args[0]
exec_args = FFI::MemoryPointer.new(:pointer, args.length + 1)
args.each_with_index do |arg, i|
exec_args[i].put_pointer(0, FFI::MemoryPointer.from_string(arg))
end
execv(cmd, exec_args)
end
end
module Kernel
alias :old_exec :exec
alias :old_exit :exit
def exec(*args); RealUnix.exec(*args); end
def exit(code = 0); RealUnix.exit(code); end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.