diff --git a/MANIFEST.md b/MANIFEST.md index 79dfa8e..c7d06cb 100644 --- a/MANIFEST.md +++ b/MANIFEST.md @@ -23,7 +23,6 @@ * lib/bsd/sys/freebsd/sys/proctable/functions.rb * lib/bsd/sys/freebsd/sys/proctable/structs.rb * lib/linux/sys/proctable.rb -* lib/sunos/sys/proctable.rb * lib/windows/sys/proctable.rb * spec/spec_helper.rb * spec/sys_proctable_aix_spec.rb @@ -31,6 +30,5 @@ * spec/sys_proctable_darwin_spec.rb * spec/sys_proctable_freebsd_spec.rb * spec/sys_proctable_linux_spec.rb -* spec/sys_proctable_sunos_spec.rb * spec/sys_proctable_windows_spec.rb * spec/sys_top_spec.rb diff --git a/README.md b/README.md index 9069c6d..3ebde5d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,6 @@ * Linux 2.6+ * FreeBSD * DragonflyBSD -* Solaris 8+ * OS X 10.7+ * AIX 5.3+ @@ -33,7 +32,6 @@ For version 1.1.5 or earlier, you may need to specify a platform in some cases. ```sh gem install sys-proctable --platform mswin32 # Windows -gem install sys-proctable --platform sunos # Solaris gem install sys-proctable --platform linux # Linux gem install sys-proctable --platform freebsd # FreeBSD gem install sys-proctable --platform darwin # OS X @@ -106,20 +104,11 @@ bundle config specific_platform true You should not have to do this for version 1.2.0 or later. -### Solaris - -The cmdline member on Solaris is limited to 80 characters unless you (or -your program) own the process. This is a Solaris design flaw/feature. - ### OS X The libproc interface is used. That means you will only get list of processes that you have access to. To get a full listing, run as root. -## Future Plans - -Support for Solaris will probably be dropped in the next major release. - ## Acknowledgements This library was originally based on the Perl module Proc::ProcessTable diff --git a/Rakefile b/Rakefile index 33b6604..86877f4 100644 --- a/Rakefile +++ b/Rakefile @@ -22,8 +22,6 @@ task :install do file = 'lib/windows/sys/proctable.rb' when /linux/i file = 'lib/linux/sys/proctable.rb' - when /sunos|solaris/i - file = 'lib/sunos/sys/proctable.rb' when /aix/i file = 'lib/aix/sys/proctable.rb' when /freebsd/i @@ -69,9 +67,6 @@ RSpec::Core::RakeTask.new(:spec) do |t| when /linux/i t.rspec_opts = '-Ilib/linux' t.pattern << 'spec/sys_proctable_linux_spec.rb' - when /sunos|solaris/i - t.rspec_opts = '-Ilib/sunos' - t.pattern << 'spec/sys_proctable_sunos_spec.rb' when /mswin|msdos|cygwin|mingw|windows/i t.rspec_opts = '-Ilib/windows' t.pattern << 'spec/sys_proctable_windows_spec.rb' diff --git a/lib/sunos/sys/proctable.rb b/lib/sunos/sys/proctable.rb deleted file mode 100644 index 29a5852..0000000 --- a/lib/sunos/sys/proctable.rb +++ /dev/null @@ -1,456 +0,0 @@ -######################################################################## -# proctable.rb -# -# A pure Ruby version of sys-proctable for SunOS 5.8 or later. -######################################################################## -require 'ffi' -require 'sys/proctable/version' - -# The Sys module serves as a namespace only. -module Sys - - # The ProcTable class encapsulates process table information. - class ProcTable - extend FFI::Library - - class Error < StandardError; end - - # There is no constructor - private_class_method :new - - private - - class Timeval < FFI::Struct - layout(:tv_sec, :time_t, :tv_usec, :time_t) - end - - class LWPSInfo < FFI::Struct - layout( - :pr_flag, :int, - :pr_lwpid, :id_t, - :pr_addr, :uintptr_t, - :pr_wchan, :uintptr_t, - :pr_stype, :char, - :pr_state, :char, - :pr_sname, :char, - :pr_nice, :char, - :pr_syscall, :short, - :pr_oldpri, :char, - :pr_cpu, :char, - :pr_pri, :int, - :pr_pctcpu, :ushort_t, - :pr_pad, :ushort_t, - :pr_start, Timeval, - :pr_time, Timeval, - :pr_clname, [:char, 8], - :pr_name, [:char, 16], - :pr_onpro, :int, - :pr_bindpro, :int, - :pr_bindpset, :int, - :pr_filler, [:int, 5] - ) - end - - class PSInfo < FFI::Struct - layout( - :pr_flag, :int, - :pr_nlwp, :int, - :pr_pid, :pid_t, - :pr_ppid, :pid_t, - :pr_pgid, :pid_t, - :pr_sid, :pid_t, - :pr_uid, :uid_t, - :pr_euid, :uid_t, - :pr_gid, :gid_t, - :pr_egid, :gid_t, - :pr_addr, :uintptr_t, - :pr_size, :size_t, - :pr_rssize, :size_t, - :pr_pad1, :size_t, - :pr_ttydev, :dev_t, - :pr_pctcpu, :ushort_t, - :pr_pctmem, :ushort_t, - :pr_start, Timeval, - :pr_time, Timeval, - :pr_ctime, Timeval, - :pr_fname, [:char, 16], - :pr_psargs, [:char, 80], - :pr_wstat, :int, - :pr_argc, :int, - :pr_argv, :uintptr_t, - :pr_envp, :uintptr_t, - :pr_dmodel, :char, - :pr_pad2, [:char, 3], - :pr_taskid, :taskid_t, - :pr_projid, :projid_t, - :pr_nzomb, :int, - :pr_poolid, :poolid_t, - :pr_zoneid, :zoneid_t, - :pr_contract, :id_t, - :pr_filler, [:int, 1], - :pr_lwp, LWPSInfo - ) - end - - class PRUsage < FFI::Struct - layout( - :pr_lwpid, :id_t, - :pr_count, :int, - :pr_tstamp, Timeval, - :pr_create, Timeval, - :pr_term, Timeval, - :pr_rtime, Timeval, - :pr_utime, Timeval, - :pr_stime, Timeval, - :pr_ttime, Timeval, - :pr_tftime, Timeval, - :pr_dftime, Timeval, - :pr_kftime, Timeval, - :pr_ltime, Timeval, - :pr_slptime, Timeval, - :pr_wtime, Timeval, - :pr_stoptime, Timeval, - :pr_filetime, [Timeval, 6], - :pr_minf, :ulong_t, - :pr_majf, :ulong_t, - :pr_nswap, :ulong_t, - :pr_inblk, :ulong_t, - :pr_oublk, :ulong_t, - :pr_msnd, :ulong_t, - :pr_mrcv, :ulong_t, - :pr_sigs, :ulong_t, - :pr_vctx, :ulong_t, - :pr_ictx, :ulong_t, - :pr_sysc, :ulong_t, - :pr_ioch, :ulong_t, - :filler, [:ulong_t, 10] - ) - end - - PRNODEV = (1</path - :contracts, # array symbolic link paths from /proc//contracts - :fd, # array of used file descriptors - :cmd_args, # array of command line arguments - :environ, # hash of environment associated with the process, - :cmdline # joined cmd_args if present, otherwise psargs - ] - - public - - ProcTableStruct = Struct.new("ProcTableStruct", *@fields) do - alias comm fname - end - - # In block form, yields a ProcTableStruct for each process entry that you - # have rights to. This method returns an array of ProcTableStruct's in - # non-block form. - # - # If a +pid+ is provided, then only a single ProcTableStruct is yielded or - # returned, or nil if no process information is found for that +pid+. - # - # Example: - # - # # Iterate over all processes - # ProcTable.ps do |proc_info| - # p proc_info - # end - # - # # Print process table information for only pid 1001 - # p ProcTable.ps(pid: 1001) - # - # # Skip prusage information - # p ProcTable.ps(prusage: false) - # - def self.ps(**kwargs) - pid = kwargs[:pid] - prusage_info = kwargs[:prusage] - - raise TypeError unless pid.is_a?(Numeric) if pid - - array = block_given? ? nil : [] - struct = nil - - Dir.foreach("/proc") do |file| - next if file =~ /\D/ # Skip non-numeric entries under /proc - - # Only return information for a given pid, if provided - next unless file.to_i == pid if pid - - # Skip over any entries we don't have permissions to read - next unless File.readable?("/proc/#{file}/psinfo") - - data = IO.read("/proc/#{file}/psinfo") rescue next - psinfo = PSInfo.new(FFI::MemoryPointer.from_string(data)) - - struct = ProcTableStruct.new - - struct.flag = psinfo[:pr_flag] - struct.nlwp = psinfo[:pr_nlwp] - struct.pid = psinfo[:pr_pid] - struct.ppid = psinfo[:pr_ppid] - struct.pgid = psinfo[:pr_pgid] - struct.sid = psinfo[:pr_sid] - struct.uid = psinfo[:pr_uid] - struct.euid = psinfo[:pr_euid] - struct.gid = psinfo[:pr_gid] - struct.egid = psinfo[:pr_egid] - struct.addr = psinfo[:pr_addr] - struct.size = psinfo[:pr_size] * 1024 # bytes - struct.rssize = psinfo[:pr_rssize] * 1024 # bytes - struct.ttydev = psinfo[:pr_ttydev] == PRNODEV ? -1 : psinfo[:pr_ttydev] - struct.pctcpu = (psinfo[:pr_pctcpu] * 100).to_f / 0x8000 - struct.pctmem = (psinfo[:pr_pctmem] * 100).to_f / 0x8000 - - struct.start = Time.at(psinfo[:pr_start][:tv_sec]) - struct.time = psinfo[:pr_time][:tv_sec] - struct.ctime = psinfo[:pr_ctime][:tv_sec] - - struct.fname = psinfo[:pr_fname].to_s - struct.psargs = psinfo[:pr_psargs].to_s - struct.wstat = psinfo[:pr_wstat] - struct.argc = psinfo[:pr_argc] - struct.argv = psinfo[:pr_argv] - struct.envp = psinfo[:pr_envp] - struct.dmodel = psinfo[:pr_dmodel] - - struct.taskid = psinfo[:pr_taskid] - struct.projid = psinfo[:pr_projid] - struct.nzomb = psinfo[:pr_nzomb] - struct.poolid = psinfo[:pr_poolid] - struct.zoneid = psinfo[:pr_zoneid] - struct.contract = psinfo[:pr_contract] - - ### LWPSINFO struct info - - struct.lwpid = psinfo[:pr_lwp][:pr_lwpid] - struct.wchan = psinfo[:pr_lwp][:pr_wchan] - struct.stype = psinfo[:pr_lwp][:pr_stype] - struct.state = psinfo[:pr_lwp][:pr_state] - struct.sname = psinfo[:pr_lwp][:pr_sname].chr - struct.nice = psinfo[:pr_lwp][:pr_nice] - struct.syscall = psinfo[:pr_lwp][:pr_syscall] - struct.pri = psinfo[:pr_lwp][:pr_pri] - struct.clname = psinfo[:pr_lwp][:pr_clname].to_s - struct.name = psinfo[:pr_lwp][:pr_name].to_s - struct.onpro = psinfo[:pr_lwp][:pr_onpro] - struct.bindpro = psinfo[:pr_lwp][:pr_bindpro] - struct.bindpset = psinfo[:pr_lwp][:pr_bindpset] - - # Get the full command line out of /proc//as. - begin - File.open("/proc/#{file}/as") do |fd| - fd.sysseek(struct.argv, IO::SEEK_SET) - address = fd.sysread(struct.argc * 4).unpack("L")[0] - - struct.cmd_args = [] - - 0.upto(struct.argc - 1){ |i| - fd.sysseek(address, IO::SEEK_SET) - data = fd.sysread(128)[/^[^\0]*/] # Null strip - struct.cmd_args << data - address += data.length + 1 # Add 1 for the space - } - - # Get the environment hash associated with the process. - struct.environ = {} - - fd.sysseek(struct.envp, IO::SEEK_SET) - - env_address = fd.sysread(128).unpack("L")[0] - - # TODO: Optimization potential here. - loop do - fd.sysseek(env_address, IO::SEEK_SET) - data = fd.sysread(1024)[/^[^\0]*/] # Null strip - break if data.empty? - key, value = data.split('=') - struct.environ[key] = value - env_address += data.length + 1 # Add 1 for the space - end - end - rescue Errno::EACCES, Errno::EBADF, Errno::EOVERFLOW, EOFError, RangeError - # Skip this if we don't have proper permissions, if there's - # no associated environment, or if there's a largefile issue. - rescue Errno::ENOENT - next # The process has terminated. Bail out! - end - - ### struct prusage - - if prusage_info != false - begin - data = IO.read("/proc/#{file}/usage") - prusage = PRUsage.new(FFI::MemoryPointer.from_string(data)) - - struct.count = prusage[:pr_count] - struct.tstamp = prusage[:pr_tstamp][:tv_sec] - struct.create = prusage[:pr_create][:tv_sec] - struct.term = prusage[:pr_term][:tv_sec] - struct.rtime = prusage[:pr_rtime][:tv_sec] - struct.utime = prusage[:pr_utime][:tv_sec] - struct.stime = prusage[:pr_stime][:tv_sec] - struct.ttime = prusage[:pr_ttime][:tv_sec] - struct.tftime = prusage[:pr_tftime][:tv_sec] - struct.dftime = prusage[:pr_dftime][:tv_sec] - struct.kftime = prusage[:pr_kftime][:tv_sec] - struct.ltime = prusage[:pr_ltime][:tv_sec] - struct.slptime = prusage[:pr_slptime][:tv_sec] - struct.wtime = prusage[:pr_wtime][:tv_sec] - struct.stoptime = prusage[:pr_stoptime][:tv_sec] - struct.minf = prusage[:pr_minf] - struct.majf = prusage[:pr_majf] - struct.nswap = prusage[:pr_nswap] - struct.inblk = prusage[:pr_inblk] - struct.oublk = prusage[:pr_oublk] - struct.msnd = prusage[:pr_msnd] - struct.mrcv = prusage[:pr_mrcv] - struct.sigs = prusage[:pr_sigs] - struct.vctx = prusage[:pr_vctx] - struct.ictx = prusage[:pr_ictx] - struct.sysc = prusage[:pr_sysc] - struct.ioch = prusage[:pr_ioch] - rescue Errno::EACCES - # Do nothing if we lack permissions. Just move on. - rescue Errno::ENOENT - next # The process has terminated. Bail out! - end - end - - # Information from /proc//path. This is represented as a hash, - # with the symbolic link name as the key, and the file it links to - # as the value, or nil if it cannot be found. - #-- - # Note that cwd information can be gathered from here, too. - struct.path = {} - - Dir["/proc/#{file}/path/*"].each{ |entry| - link = File.readlink(entry) rescue nil - struct.path[File.basename(entry)] = link - } - - # Information from /proc//contracts. This is represented as - # a hash, with the symbolic link name as the key, and the file - # it links to as the value. - struct.contracts = {} - - Dir["/proc/#{file}/contracts/*"].each{ |entry| - link = File.readlink(entry) rescue nil - struct.contracts[File.basename(entry)] = link - } - - # Information from /proc//fd. This returns an array of - # numeric file descriptors used by the process. - struct.fd = Dir["/proc/#{file}/fd/*"].map{ |f| File.basename(f).to_i } - - # Use the cmd_args as the cmdline if available. Otherwise use - # the psargs. This struct member is provided to provide a measure - # of consistency with the other platform implementations. - if struct.cmd_args && struct.cmd_args.length > 0 - struct.cmdline = struct.cmd_args.join(' ') - else - struct.cmdline = struct.psargs - end - - # This is read-only data - struct.freeze - - if block_given? - yield struct - else - array << struct - end - end - - pid ? struct : array - end - - # Returns an array of fields that each ProcTableStruct will contain. This - # may be useful if you want to know in advance what fields are available - # without having to perform at least one read of the /proc table. - # - # Example: - # - # Sys::ProcTable.fields.each{ |field| - # puts "Field: #{field}" - # } - # - def self.fields - @fields.map(&:to_s) - end - end -end diff --git a/lib/sys/proctable.rb b/lib/sys/proctable.rb index e86b6fe..20cbe55 100644 --- a/lib/sys/proctable.rb +++ b/lib/sys/proctable.rb @@ -9,8 +9,6 @@ require_relative '../bsd/sys/proctable' when /linux/i require_relative '../linux/sys/proctable' - when /sunos|solaris/i - require_relative '../sunos/sys/proctable' when /mswin|win32|dos|cygwin|mingw|windows/i require_relative '../windows/sys/proctable' else diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 204db51..e861642 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,6 @@ config.filter_run_excluding(:bsd) unless RbConfig::CONFIG['host_os'] =~ /bsd|dragonfly/i config.filter_run_excluding(:freebsd) unless RbConfig::CONFIG['host_os'] =~ /freebsd/i config.filter_run_excluding(:dragonfly) unless RbConfig::CONFIG['host_os'] =~ /dragonfly/i - config.filter_run_excluding(:sunos) unless RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i config.filter_run_excluding(:windows) unless Gem.win_platform? config.filter_run_excluding(:jruby) if RUBY_PLATFORM == 'java' end diff --git a/spec/sys_proctable_sunos_spec.rb b/spec/sys_proctable_sunos_spec.rb deleted file mode 100644 index e0e8e9c..0000000 --- a/spec/sys_proctable_sunos_spec.rb +++ /dev/null @@ -1,314 +0,0 @@ -####################################################################### -# sys_proctable_sunos_spec.rb -# -# Test suite for sys-proctable for SunOS/Solaris. This should be run -# run via the 'rake spec' task. -####################################################################### -require 'spec_helper' - -RSpec.describe Sys::ProcTable, :sunos do - let(:fields){ - %w[ - flag nlwp pid ppid pgid sid uid euid gid egid addr size - rssize ttydev pctcpu pctmem start time ctime fname psargs - wstat argc argv envp dmodel taskid projid nzomb poolid - zoneid contract lwpid wchan stype state sname nice syscall - pri clname name onpro bindpro bindpset count tstamp create - term rtime utime stime ttime tftime dftime kftime ltime - slptime wtime stoptime minf majf nswap inblk oublk msnd - mrcv sigs vctx ictx sysc ioch path contracts fd cmd_args - environ cmdline - ] - } - - context 'fields singleton method' do - it 'responds to a fields method' do - expect(described_class).to respond_to(:fields) - end - - it 'returns the expected results for the fields method' do - expect(described_class.fields).to be_kind_of(Array) - expect(described_class.fields).to eql(fields) - end - end - - context 'ProcTable::Struct members' do - subject(:process){ described_class.ps(:pid => Process.pid) } - - it 'contains a pid member and returns the expected value' do - expect(process).to respond_to(:pid) - expect(process.pid).to be_kind_of(Numeric) - expect(process.pid).to eql(Process.pid) - end - - it 'contains a ppid member and returns the expected value' do - expect(process).to respond_to(:ppid) - expect(process.ppid).to be_kind_of(Numeric) - expect(process.ppid).to eql(Process.ppid) - end - - it 'contains a pgid member and returns the expected value' do - expect(process).to respond_to(:pgid) - expect(process.pgid).to be_kind_of(Numeric) - expect(process.pgid).to eql(Process.getpgrp) - end - - it 'has a flag member that returns the expected value' do - expect(process).to respond_to(:flag) - expect(process.flag).to be_kind_of(Integer) - end - - it 'has an nlwp member that returns the expected value' do - expect(process).to respond_to(:nlwp) - expect(process.nlwp).to be_kind_of(Integer) - expect(process.nlwp).to be >= 0 - end - - it 'has a sid member that returns the expected value' do - expect(process).to respond_to(:sid) - expect(process.sid).to be_kind_of(Integer) - expect(process.sid).to be >= 0 - end - - it 'has a uid member that returns the expected value' do - expect(process).to respond_to(:uid) - expect(process.uid).to be_kind_of(Integer) - expect(process.uid).to eql(Process.uid) - end - - it 'has a euid member that returns the expected value' do - expect(process).to respond_to(:euid) - expect(process.euid).to be_kind_of(Integer) - expect(process.euid).to eql(Process.euid) - end - - it 'has a gid member that returns the expected value' do - expect(process).to respond_to(:gid) - expect(process.gid).to be_kind_of(Integer) - expect(process.gid).to eql(Process.gid) - end - - it 'has a egid member that returns the expected value' do - expect(process).to respond_to(:egid) - expect(process.egid).to be_kind_of(Integer) - expect(process.egid).to eql(Process.egid) - end - - it 'has an addr member that returns the expected value' do - expect(process).to respond_to(:addr) - expect(process.addr).to be_kind_of(Integer) - expect(process.addr).to be >= 0 - end - - it 'has a size member that returns the expected value' do - expect(process).to respond_to(:size) - expect(process.size).to be_kind_of(Integer) - expect(process.size).to be >= 0 - end - - it 'has a rssize member that returns the expected value' do - expect(process).to respond_to(:rssize) - expect(process.rssize).to be_kind_of(Integer) - expect(process.rssize).to be >= 0 - end - - it 'has a ttydev member that returns the expected value' do - expect(process).to respond_to(:ttydev) - expect(process.ttydev).to be_kind_of(Integer) - expect(process.ttydev).to be >= -1 - end - - it 'has a pctcpu member that returns the expected value' do - expect(process).to respond_to(:pctcpu) - expect(process.pctcpu).to be_kind_of(Float) - expect(process.pctcpu).to be >= 0.0 - end - - it 'has a pctmem member that returns the expected value' do - expect(process).to respond_to(:pctmem) - expect(process.pctmem).to be_kind_of(Float) - expect(process.pctmem).to be >= 0.0 - end - - it 'has a start member that returns the expected value' do - expect(process).to respond_to(:start) - expect(process.start).to be_kind_of(Time) - end - - it 'has a time member that returns the expected value' do - expect(process).to respond_to(:time) - expect(process.time).to be_kind_of(Integer) - expect(process.time).to be >= 0 - end - - it 'has a ctime member that returns the expected value' do - expect(process).to respond_to(:ctime) - expect(process.ctime).to be_kind_of(Integer) - expect(process.ctime).to be >= 0 - end - - it 'has a fname member that returns the expected value' do - expect(process).to respond_to(:fname) - expect(process.fname).to be_kind_of(String) - expect(process.fname.size).to be > 0 - end - - it 'has a comm alias member' do - expect(process.method(:comm)).to eql(process.method(:fname)) - end - - it 'has a psargs member that returns the expected value' do - expect(process).to respond_to(:psargs) - expect(process.psargs).to be_kind_of(String) - expect(process.psargs.size).to be > 0 - end - - it 'has a wstat member that returns the expected value' do - expect(process).to respond_to(:wstat) - expect(process.wstat).to be_kind_of(Integer) - expect(process.wstat).to be >= 0 - end - - it 'has an args member that returns the expected value' do - expect(process).to respond_to(:argc) - expect(process.argc).to be_kind_of(Integer) - expect(process.argc).to be >= 0 - end - - it 'has an argv member that returns the expected value' do - expect(process).to respond_to(:argv) - expect(process.argv).to be_kind_of(Integer) - expect(process.argv).to be >= 0 - end - - it 'has a envp member that returns the expected value' do - expect(process).to respond_to(:envp) - expect(process.envp).to be_kind_of(Integer) - expect(process.envp).to be >= 0 - end - - it 'has a dmodel member that returns the expected value' do - expect(process).to respond_to(:dmodel) - expect(process.dmodel).to be_kind_of(Integer) - expect(process.dmodel).to be >= 0 - end - - it 'has a taskid member that returns the expected value' do - expect(process).to respond_to(:taskid) - expect(process.taskid).to be_kind_of(Integer) - expect(process.taskid).to be >= 0 - end - - it 'has a projid member that returns the expected value' do - expect(process).to respond_to(:projid) - expect(process.projid).to be_kind_of(Integer) - expect(process.projid).to be >= 0 - end - - it 'has a nzomb member that returns the expected value' do - expect(process).to respond_to(:nzomb) - expect(process.nzomb).to be_kind_of(Integer) - expect(process.nzomb).to be >= 0 - end - - it 'has a poolid member that returns the expected value' do - expect(process).to respond_to(:poolid) - expect(process.poolid).to be_kind_of(Integer) - expect(process.poolid).to be >= 0 - end - - it 'has a zoneid member that returns the expected value' do - expect(process).to respond_to(:zoneid) - expect(process.zoneid).to be_kind_of(Integer) - expect(process.zoneid).to be >= 0 - end - - it 'has a contract member that returns the expected value' do - expect(process).to respond_to(:contract) - expect(process.contract).to be_kind_of(Integer) - expect(process.contract).to be >= 0 - end - end - - context 'lwpsinfo struct' do - subject(:process){ described_class.ps(:pid => Process.pid) } - - it 'has a lwpid member that returns the expected value' do - expect(process).to respond_to(:lwpid) - expect(process.lwpid).to be_kind_of(Integer) - expect(process.lwpid).to be >= 0 - end - - it 'has a wchan member that returns the expected value' do - expect(process).to respond_to(:wchan) - expect(process.wchan).to be_kind_of(Integer) - expect(process.wchan).to be >= 0 - end - - it 'has a stype member that returns the expected value' do - expect(process).to respond_to(:stype) - expect(process.stype).to be_kind_of(Integer) - expect(process.stype).to be >= 0 - end - - it 'has a state member that returns the expected value' do - expect(process).to respond_to(:state) - expect(process.state).to be_kind_of(Integer) - expect(process.state).to be >= 0 - end - - it 'has a sname member that returns the expected value' do - expect(process).to respond_to(:sname) - expect(process.sname).to be_kind_of(String) - expect(%w[S R Z T I O]).to include(process.sname) - end - - it 'has a nice member that returns the expected value' do - expect(process).to respond_to(:nice) - expect(process.nice).to be_kind_of(Integer) - expect(process.nice).to be >= 0 - end - - it 'has a syscall member that returns the expected value' do - expect(process).to respond_to(:syscall) - expect(process.syscall).to be_kind_of(Integer) - expect(process.syscall).to be >= 0 - end - - it 'has a pri member that returns the expected value' do - expect(process).to respond_to(:pri) - expect(process.pri).to be_kind_of(Integer) - expect(process.pri).to be >= 0 - end - - it 'has a clname member that returns the expected value' do - expect(process).to respond_to(:clname) - expect(process.clname).to be_kind_of(String) - expect(process.clname.size).to be_between(0, 8) - end - - it 'has a name member that returns the expected value' do - expect(process).to respond_to(:name) - expect(process.name).to be_kind_of(String) - expect(process.name.size).to be_between(0, 16) - end - - it 'has an onpro member that returns the expected value' do - expect(process).to respond_to(:onpro) - expect(process.onpro).to be_kind_of(Integer) - expect(process.onpro).to be >= 0 - end - - it 'has a bindpro member that returns the expected value' do - expect(process).to respond_to(:bindpro) - expect(process.bindpro).to be_kind_of(Integer) - expect(process.bindpro).to be >= -1 - end - - it 'has a bindpset member that returns the expected value' do - expect(process).to respond_to(:bindpset) - expect(process.bindpset).to be_kind_of(Integer) - expect(process.bindpset).to be >= -1 - end - end -end