fork.cr

libc's fork(2) for Crystal

fork.cr

libc's fork for Crystal.

Features

  • Provides a Fork.fork function.
  • Provides a Fork.wait function.
  • Provides a Fork.waitpid function.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      fork:
        github: postmodern/fork.cr
    
  2. Run shards install

Usage

require "fork"

if (pid = Fork.fork) == 0
  # running in child process

  # exit with status -1
  exit -1
else
  # running in parent process

  status = Fork.waitpid(pid) # wait for the child process to exit
  puts "Child process exiting with status: #{status}"
end

Using fork with a block:

status = Fork.fork do
  # running in child process

  # exit with status -1
  exit -1
end

puts "Child process exiting with status: #{status}"

Contributing

  1. Fork it (https://github.com/postmodern/fork/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

fork.cr

Owner
Statistic
  • 2
  • 0
  • 2
  • 0
  • 1
  • almost 3 years ago
  • July 24, 2021
License

MIT License

Links
Synced at

Sun, 19 May 2024 07:53:10 GMT

Languages