fork

Version, currently main branch1 version
  • main branchlatestJul 24, 2021

github.com/crystal-posix/fork.cr

libc's fork(2) for Crystal

2 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  fork:
    github: crystal-posix/fork.cr
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
1.1.0
License
MIT
Author
Postmodern

Dependencies

Development Dependencies

  • spectator~> 0.9, >= 0.9.9gitlab: arctic-fox/spectatordev

README

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