Skip to content

Instantly share code, notes, and snippets.

@zlx
Created July 2, 2014 14:25
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 zlx/9bca5ab1a6c8a6b5475f to your computer and use it in GitHub Desktop.
Save zlx/9bca5ab1a6c8a6b5475f to your computer and use it in GitHub Desktop.
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
@zlx
Copy link
Author

zlx commented Jul 2, 2014

输出:

Heavy lifting accomplished!
Heavy lifting accomplished!
Feather lifting accomplished!
Feather lifting accomplished!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment