Created
July 2, 2014 14:25
-
-
Save zlx/9bca5ab1a6c8a6b5475f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
child_socket, parent_socket = Socket.pair(:UNIX, :DGRAM, 0) | |
maxlen = 1000 | |
fork do | |
parent_socket.close | |
4.times do | |
instruction = child_socket.recv(maxlen) | |
child_socket.send("#{instruction} accomplished!", 0) | |
end | |
end | |
child_socket.close | |
2.times do | |
parent_socket.send("Heavy lifting", 0) | |
end | |
2.times do | |
parent_socket.send("Feather lifting", 0) | |
end | |
4.times do | |
$stdout.puts parent_socket.recv(maxlen) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
输出: