Skip to content
Kward Search API index

Module: Kward::NativeShell::Jobs

Included in:
Runtime
Defined in:
lib/kward/shell/native_jobs.rb

Overview

Each job has an owned process group. Only its interpreter leader is reaped here; that interpreter owns the pipeline and substitution children.

Defined Under Namespace

Classes: Job

Constant Summary collapse

MAX_JOBS =
1_024
TCSETPGRP =
Fiddle::Function.new(Fiddle::Handle::DEFAULT["tcsetpgrp"], [Fiddle::TYPE_INT, Fiddle::TYPE_INT], Fiddle::TYPE_INT)

Instance Method Summary collapse

Instance Method Details

#close ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kward/shell/native_jobs.rb', line 22

def close
  active = @jobs.values.reject { |job| job.state == :done }
  active.each do |job|
    signal_job(job, "HUP")
    signal_job(job, "CONT")
    signal_job(job, "KILL")
  end
  active.each do |job|
    begin
      Process.waitpid(job.pid)
    rescue Errno::ECHILD
      # A completed job may already have been collected by its waiter.
    end
  end
  @jobs.clear
ensure
  close_resources
end

#notify_jobs(error:, force: false) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/kward/shell/native_jobs.rb', line 12

def notify_jobs(error:, force: false)
  return unless interactive_scope? && (force || @options.include?("notify"))
  reap_jobs
  @jobs.each_value do |job|
    next if job.state == :running || job.notified == job.state
    error&.puts("[#{job.id}] #{job.state.to_s.capitalize} #{job.command}")
    job.notified = job.state
  end
end