Sha256: 0aa016d0734fc8d8b86306cdf563759589ab70690e802f2bba0792ce2b247ca1

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved.
# This is free software with ABSOLUTELY NO WARRANTY.
# You can redistribute it and/or modify it under the terms of the GNU GPL 2.

$LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..'
require 'qwik/util-pathname'

module PidModule
  def write_pid_file(pidfile)
    pidfile.path.put("#{Process.pid}\n")
  end

  def read_pid_file(pidfile)
    pid = nil
    pid = pidfile.path.get_first.chomp.to_i
    return pid
  end

  def remove_pid_file(pidfile)
    if Process.pid == read_pid_file(pidfile)
      pidfile.path.unlink
    end
  end

  # for test
  def exist_pid_file?(pidfile)
    return pidfile.path.exist?
  end
end

if $0 == __FILE__
  require 'test/unit'
  $test = true
end

if defined?($test) && $test
  class TestUtilPid < Test::Unit::TestCase
    include PidModule

    def test_all
      f = 'test-pid.txt'

      # test_exist_pid_file?
      assert_equal false, exist_pid_file?(f)

      # test_write_pid_file
      write_pid_file(f)
      assert_equal true, exist_pid_file?(f)

      # test_read_pid_file
      assert_equal Process.pid, read_pid_file(f)
      
      # test_remove_pid_file
      remove_pid_file(f)
      assert_equal false, exist_pid_file?(f)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
qwik2md-2.0.1 vendor/qwik/lib/qwik/util-pid.rb
qwik2md-2.0.0 vendor/qwik/lib/qwik/util-pid.rb
qwik2md-1.0.2 vendor/qwik/lib/qwik/util-pid.rb
qwik2md-1.0.1 vendor/qwik/lib/qwik/util-pid.rb
qwik2md-1.0.0 vendor/qwik/lib/qwik/util-pid.rb
qwik2md-0.1.0 vendor/qwik/lib/qwik/util-pid.rb
qwikdoc-0.0.1 vendor/qwik/util-pid.rb