I’d like to play with Unix system calls, ideally from Ruby. How can I do so?
I’ve heard about Fiddle, but I don’t know where to begin / which C library should I attach it to?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume by “interactively” you mean via
irb.A high-level language like Ruby is going to provide wrappers for most kernel syscalls, of varying thickness.
Occasionally these wrappers will be very thin, as with
sysread()andsyswrite(). These are more or less equivalent toread(2)andwrite(2), respectively.Other syscalls will be hidden behind thicker layers, such as with the socket I/O stuff. I don’t know if calling
UNIXSocket.recv()counts as “calling a syscall” precisely. At some level, that’s exactly what happens, but who knows how much Ruby and C code stands between you and the actual system call.Then there are those syscalls that aren’t in the standard Ruby API at all, most likely because they don’t make a great amount of sense to be, like
mmap(2). That syscall is all about raw pointers to memory, something you’ve chosen to avoid by using a language like Ruby in the first place. There happens to be a third party Ruby mmap module, but it’s really not going to give you all the power you can tap from C.The
syscall()interface Mat pointed out in the comment above is a similar story: in theory, it lets you call any system call in the kernel. But, if you don’t have the ability to deal with pointers, lay out data precisely in memory for structures, etc., your ability to make useful calls is going to be quite limited.If you want to play with system calls, learn C. There is no shortcut.