linux_stat 1.4.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +195 -104
 - data/bin/console +7 -1
 - data/exe/linuxstat.rb +8 -1
 - data/ext/fs_stat/fs_stat.c +10 -10
 - data/ext/nproc/nproc.c +2 -2
 - data/ext/procfs/extconf.rb +11 -0
 - data/ext/procfs/loadavg_pid.h +11 -0
 - data/ext/procfs/procfs.c +42 -0
 - data/ext/procfs/stat.h +98 -0
 - data/ext/procfs/statm.h +109 -0
 - data/ext/procfs/uptime.h +12 -0
 - data/ext/sysconf/extconf.rb +1 -1
 - data/ext/sysconf/sysconf.c +27 -27
 - data/ext/sysinfo/extconf.rb +11 -0
 - data/ext/sysinfo/sysinfo.c +177 -0
 - data/ext/utsname/utsname.c +1 -1
 - data/lib/linux_stat.rb +10 -4
 - data/lib/linux_stat/battery.rb +8 -1
 - data/lib/linux_stat/memory.rb +13 -3
 - data/lib/linux_stat/net.rb +5 -5
 - data/lib/linux_stat/os.rb +56 -9
 - data/lib/linux_stat/process.rb +17 -27
 - data/lib/linux_stat/process_info.rb +102 -121
 - data/lib/linux_stat/swap.rb +36 -9
 - data/lib/linux_stat/version.rb +1 -1
 - metadata +13 -3
 
    
        data/bin/console
    CHANGED
    
    | 
         @@ -1,4 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            $-v = true
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            begin
         
     | 
| 
      
 5 
     | 
    
         
            +
            	%w(linux_stat irb).each(&method(:require))
         
     | 
| 
      
 6 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 7 
     | 
    
         
            +
            	abort "LinuxStat and IRB shoud be installed before you can run LinuxStat console"
         
     | 
| 
      
 8 
     | 
    
         
            +
            end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       4 
10 
     | 
    
         
             
            IRB.start(__FILE__)
         
     | 
    
        data/exe/linuxstat.rb
    CHANGED
    
    | 
         @@ -7,6 +7,12 @@ rescue LoadError 
     | 
|
| 
       7 
7 
     | 
    
         
             
            	abort "The Gem needs to be installed before this test can be run!"
         
     | 
| 
       8 
8 
     | 
    
         
             
            end
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
      
 10 
     | 
    
         
            +
            Integer.class_exec do
         
     | 
| 
      
 11 
     | 
    
         
            +
            	define_method(:clamp) { |min, max|
         
     | 
| 
      
 12 
     | 
    
         
            +
            		self < min ? min : self > max ? max : self
         
     | 
| 
      
 13 
     | 
    
         
            +
            	}
         
     | 
| 
      
 14 
     | 
    
         
            +
            end unless 1.respond_to?(:clamp)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
       10 
16 
     | 
    
         
             
            # Gradient colour to strings
         
     | 
| 
       11 
17 
     | 
    
         
             
            class String
         
     | 
| 
       12 
18 
     | 
    
         
             
            	def colourize(colour = 1, flip: false)
         
     | 
| 
         @@ -138,7 +144,8 @@ execute.sort.each do |c| 
     | 
|
| 
       138 
144 
     | 
    
         
             
            					param << "#{p[1] || 'arg'}#{_arg}, "
         
     | 
| 
       139 
145 
     | 
    
         
             
            			end
         
     | 
| 
       140 
146 
     | 
    
         
             
            		end
         
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
            		param.chomp!(", ")
         
     | 
| 
       142 
149 
     | 
    
         | 
| 
       143 
150 
     | 
    
         
             
            		disp_meth = "#{meth}"
         
     | 
| 
       144 
151 
     | 
    
         
             
            		disp_meth.concat(arg ? "(#{param})" : "(#{param})")
         
     | 
    
        data/ext/fs_stat/fs_stat.c
    CHANGED
    
    | 
         @@ -18,16 +18,16 @@ static VALUE statfs(VALUE obj, VALUE dir) { 
     | 
|
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
            	if(statvfs(d, &buf) < 0) return hash ;
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX(buf.f_bsize)) ;
         
     | 
| 
       22 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")),  
     | 
| 
       23 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("blocks")),  
     | 
| 
       24 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_free")),  
     | 
| 
       25 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")),  
     | 
| 
       26 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("inodes")),  
     | 
| 
       27 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")),  
     | 
| 
       28 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")),  
     | 
| 
       29 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")),  
     | 
| 
       30 
     | 
    
         
            -
            	rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")),  
     | 
| 
      
 21 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX((unsigned int)buf.f_bsize)) ;
         
     | 
| 
      
 22 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), ULL2NUM((unsigned long long)buf.f_frsize)) ;
         
     | 
| 
      
 23 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), ULL2NUM((unsigned long long)buf.f_blocks)) ;
         
     | 
| 
      
 24 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), ULL2NUM((unsigned long long)buf.f_bfree)) ;
         
     | 
| 
      
 25 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), ULL2NUM((unsigned long long)buf.f_bavail)) ;
         
     | 
| 
      
 26 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), ULL2NUM((unsigned long long)buf.f_files)) ;
         
     | 
| 
      
 27 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), ULL2NUM((unsigned long long)buf.f_ffree)) ;
         
     | 
| 
      
 28 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), ULL2NUM((unsigned long long)buf.f_fsid)) ;
         
     | 
| 
      
 29 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), ULL2NUM((unsigned long long)buf.f_flag)) ;
         
     | 
| 
      
 30 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), ULL2NUM((unsigned long long)buf.f_namemax)) ;
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
32 
     | 
    
         
             
            	return hash ;
         
     | 
| 
       33 
33 
     | 
    
         
             
            }
         
     | 
    
        data/ext/nproc/nproc.c
    CHANGED
    
    | 
         @@ -18,9 +18,9 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
            static VALUE count_cpu_for_pid(VALUE obj, VALUE pid) {
         
     | 
| 
       19 
19 
     | 
    
         
             
            	cpu_set_t set ;
         
     | 
| 
       20 
20 
     | 
    
         
             
            	CPU_ZERO(&set) ;
         
     | 
| 
       21 
     | 
    
         
            -
            	 
     | 
| 
      
 21 
     | 
    
         
            +
            	char status = sched_getaffinity(FIX2INT(pid), sizeof(set), &set) ;
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
            	if ( 
     | 
| 
      
 23 
     | 
    
         
            +
            	if (status < 0) return Qnil ;
         
     | 
| 
       24 
24 
     | 
    
         
             
            	return INT2FIX(CPU_COUNT(&set)) ;
         
     | 
| 
       25 
25 
     | 
    
         
             
            }
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'mkmf'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            unless have_const('linux') || RbConfig::CONFIG['arch'].to_s[/linux/]
         
     | 
| 
      
 4 
     | 
    
         
            +
            	abort('Platform is not linux')
         
     | 
| 
      
 5 
     | 
    
         
            +
            end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            unless have_header('unistd.h') && have_header('ruby.h')
         
     | 
| 
      
 8 
     | 
    
         
            +
            	abort('Missing header')
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            create_makefile 'linux_stat/procfs'
         
     | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            VALUE last_pid(VALUE obj) {
         
     | 
| 
      
 2 
     | 
    
         
            +
            	FILE *f = fopen("/proc/loadavg", "r") ;
         
     | 
| 
      
 3 
     | 
    
         
            +
            	if (!f) return Qnil ;
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            	unsigned long long _last_pid ;
         
     | 
| 
      
 6 
     | 
    
         
            +
            	char status = fscanf(f, "%*f %*f %*f %*s %llu", &_last_pid) ;
         
     | 
| 
      
 7 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 8 
     | 
    
         
            +
            	if (status != 1) return Qnil ;
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            	return ULL2NUM(_last_pid) ;
         
     | 
| 
      
 11 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/procfs/procfs.c
    ADDED
    
    | 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // ProcFS doesn't include all the /proc/ files.
         
     | 
| 
      
 2 
     | 
    
         
            +
            // It includes some of them that can add potential
         
     | 
| 
      
 3 
     | 
    
         
            +
            // performance boost to the LinuxStat modules.
         
     | 
| 
      
 4 
     | 
    
         
            +
            //
         
     | 
| 
      
 5 
     | 
    
         
            +
            // Some LinuxStat modules reads /proc/ files
         
     | 
| 
      
 6 
     | 
    
         
            +
            // that are not present here. That is because
         
     | 
| 
      
 7 
     | 
    
         
            +
            // Ruby can handle them well with little wastage.
         
     | 
| 
      
 8 
     | 
    
         
            +
            // Adding C may be a potential risk in such places.
         
     | 
| 
      
 9 
     | 
    
         
            +
            //
         
     | 
| 
      
 10 
     | 
    
         
            +
            // In this ProcFS module, we will define the methods
         
     | 
| 
      
 11 
     | 
    
         
            +
            // that really gets the benefit.
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            #include <stdio.h>
         
     | 
| 
      
 14 
     | 
    
         
            +
            #include <unistd.h>
         
     | 
| 
      
 15 
     | 
    
         
            +
            #include <string.h>
         
     | 
| 
      
 16 
     | 
    
         
            +
            #include "ruby.h"
         
     | 
| 
      
 17 
     | 
    
         
            +
            #include "uptime.h"
         
     | 
| 
      
 18 
     | 
    
         
            +
            #include "statm.h"
         
     | 
| 
      
 19 
     | 
    
         
            +
            #include "stat.h"
         
     | 
| 
      
 20 
     | 
    
         
            +
            #include "loadavg_pid.h"
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            int Init_procfs() {
         
     | 
| 
      
 23 
     | 
    
         
            +
            	VALUE _linux_stat = rb_define_module("LinuxStat") ;
         
     | 
| 
      
 24 
     | 
    
         
            +
            	VALUE _procfs = rb_define_module_under(_linux_stat, "ProcFS") ;
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            	// uptime
         
     | 
| 
      
 27 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "uptime_f", uptime_f, 0) ;
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            	// statm
         
     | 
| 
      
 30 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "statm_memory", statm_memory, 1) ;
         
     | 
| 
      
 31 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "statm", statm, 1) ;
         
     | 
| 
      
 32 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "statm_virtual", statm_virtual, 1) ;
         
     | 
| 
      
 33 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "statm_resident", statm_resident, 1) ;
         
     | 
| 
      
 34 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "statm_shared", statm_shared, 1) ;
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            	// loadavg last PID
         
     | 
| 
      
 37 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "last_pid", last_pid, 0) ;
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            	// stat
         
     | 
| 
      
 40 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "ps_state", ps_state, 1) ;
         
     | 
| 
      
 41 
     | 
    
         
            +
            	rb_define_module_function(_procfs, "ps_stat", ps_stat, 1) ;
         
     | 
| 
      
 42 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/procfs/stat.h
    ADDED
    
    | 
         @@ -0,0 +1,98 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            VALUE ps_state(VALUE obj, VALUE pid) {
         
     | 
| 
      
 2 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 3 
     | 
    
         
            +
            	if (_pid < 0) return rb_str_new_cstr("") ;
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 6 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/stat", _pid) ;
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 9 
     | 
    
         
            +
            	if (!f) return rb_str_new_cstr("") ;
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            	char _s[1] ;
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            	char status = fscanf(f, "%*llu (%*[^)]%*[)] %s", _s) ;
         
     | 
| 
      
 14 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            	if (status != 1) return rb_str_new_cstr("") ;
         
     | 
| 
      
 17 
     | 
    
         
            +
            	return rb_str_new_cstr(_s) ;
         
     | 
| 
      
 18 
     | 
    
         
            +
            }
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
            VALUE ps_stat(VALUE obj, VALUE pid) {
         
     | 
| 
      
 21 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 22 
     | 
    
         
            +
            	if (_pid < 0) return rb_str_new_cstr("") ;
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 25 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/stat", _pid) ;
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            	if (!f)
         
     | 
| 
      
 30 
     | 
    
         
            +
            		return rb_ary_new() ;
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            	// ?? JEEZ !!
         
     | 
| 
      
 33 
     | 
    
         
            +
            	// We need to do this because the datatypes are different
         
     | 
| 
      
 34 
     | 
    
         
            +
            	// Can't make an array like Ruby out of String
         
     | 
| 
      
 35 
     | 
    
         
            +
            	// This is hard to write and check, but tested, and works.
         
     | 
| 
      
 36 
     | 
    
         
            +
            	//
         
     | 
| 
      
 37 
     | 
    
         
            +
            	// For this struct,
         
     | 
| 
      
 38 
     | 
    
         
            +
            	// follow https://man7.org/linux/man-pages/man5/proc.5.html
         
     | 
| 
      
 39 
     | 
    
         
            +
            	int ppid, pgrp, session, tty_nr, tpgid ;
         
     | 
| 
      
 40 
     | 
    
         
            +
            	unsigned flags ;
         
     | 
| 
      
 41 
     | 
    
         
            +
            	long unsigned minflt, cminflt, majflt, cmajflt, utime, stime ;
         
     | 
| 
      
 42 
     | 
    
         
            +
            	long cutime, cstime, priority, nice, num_threads, itrealvalue ;
         
     | 
| 
      
 43 
     | 
    
         
            +
            	long long unsigned starttime ;
         
     | 
| 
      
 44 
     | 
    
         
            +
            	long unsigned vsize ;
         
     | 
| 
      
 45 
     | 
    
         
            +
            	long rss ;
         
     | 
| 
      
 46 
     | 
    
         
            +
            	long unsigned rsslim, startcode, endcode, startstack, kstkesp, kstkeip ;
         
     | 
| 
      
 47 
     | 
    
         
            +
            	long unsigned signal, blocked, sigignore, sigcatch, wchan, nswap, cnswap ;
         
     | 
| 
      
 48 
     | 
    
         
            +
            	int exit_signal, processor ;
         
     | 
| 
      
 49 
     | 
    
         
            +
            	unsigned rt_priority, policy ;
         
     | 
| 
      
 50 
     | 
    
         
            +
            	long long unsigned delayacct_blkio_ticks ;
         
     | 
| 
      
 51 
     | 
    
         
            +
            	long unsigned guest_time ;
         
     | 
| 
      
 52 
     | 
    
         
            +
            	long cguest_time ;
         
     | 
| 
      
 53 
     | 
    
         
            +
            	long unsigned start_data, end_data, start_brk, arg_start, arg_end ;
         
     | 
| 
      
 54 
     | 
    
         
            +
            	long unsigned env_start, env_end ;
         
     | 
| 
      
 55 
     | 
    
         
            +
            	int exit_code ;
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            	char status = fscanf(
         
     | 
| 
      
 58 
     | 
    
         
            +
            		f, "%*llu (%*[^)]%*[)] %*c "
         
     | 
| 
      
 59 
     | 
    
         
            +
            		"%d %d %d %d %d %u "
         
     | 
| 
      
 60 
     | 
    
         
            +
            		"%lu %lu %lu %lu %lu %lu "
         
     | 
| 
      
 61 
     | 
    
         
            +
            		"%ld %ld %ld %ld %ld %ld "
         
     | 
| 
      
 62 
     | 
    
         
            +
            		"%llu %lu %ld %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu "
         
     | 
| 
      
 63 
     | 
    
         
            +
            		"%d %d %u %u %llu %lu %ld %lu %lu %lu %lu %lu %lu %lu %d", &ppid, &pgrp,
         
     | 
| 
      
 64 
     | 
    
         
            +
            		&session, &tty_nr, &tpgid, &flags, &minflt, &cminflt, &majflt, &cmajflt, &utime, &stime, &cutime,
         
     | 
| 
      
 65 
     | 
    
         
            +
            		&cstime, &priority, &nice, &num_threads, &itrealvalue, &starttime, &vsize, &rss, &rsslim,
         
     | 
| 
      
 66 
     | 
    
         
            +
            		&startcode, &endcode, &startstack, &kstkesp, &kstkeip, &signal, &blocked, &sigignore,
         
     | 
| 
      
 67 
     | 
    
         
            +
            		&sigcatch, &wchan, &nswap, &cnswap, &exit_signal, &processor, &rt_priority, &policy,
         
     | 
| 
      
 68 
     | 
    
         
            +
            		&delayacct_blkio_ticks, &guest_time, &cguest_time, &start_data, &end_data,
         
     | 
| 
      
 69 
     | 
    
         
            +
            		&start_brk, &arg_start, &arg_end, &env_start, &env_end, &exit_code
         
     | 
| 
      
 70 
     | 
    
         
            +
            	) ;
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            	if (status != 49)
         
     | 
| 
      
 75 
     | 
    
         
            +
            		return rb_ary_new() ;
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            	return rb_ary_new_from_args(49,
         
     | 
| 
      
 78 
     | 
    
         
            +
            	INT2NUM(ppid), INT2NUM(pgrp), INT2NUM(session), INT2NUM(tty_nr), INT2NUM(tpgid),
         
     | 
| 
      
 79 
     | 
    
         
            +
            	UINT2NUM(flags),
         
     | 
| 
      
 80 
     | 
    
         
            +
            	ULONG2NUM(minflt), ULONG2NUM(cminflt), ULONG2NUM(majflt), ULONG2NUM(cmajflt),
         
     | 
| 
      
 81 
     | 
    
         
            +
            	ULONG2NUM(utime), ULONG2NUM(stime),
         
     | 
| 
      
 82 
     | 
    
         
            +
            	LONG2NUM(cutime), LONG2NUM(cstime), LONG2NUM(priority),
         
     | 
| 
      
 83 
     | 
    
         
            +
            	LONG2NUM(nice), LONG2NUM(num_threads), LONG2NUM(itrealvalue),
         
     | 
| 
      
 84 
     | 
    
         
            +
            	ULL2NUM(starttime),
         
     | 
| 
      
 85 
     | 
    
         
            +
            	ULONG2NUM(vsize),
         
     | 
| 
      
 86 
     | 
    
         
            +
            	LONG2NUM(rss),
         
     | 
| 
      
 87 
     | 
    
         
            +
            	ULONG2NUM(rsslim), ULONG2NUM(startcode), ULONG2NUM(endcode),
         
     | 
| 
      
 88 
     | 
    
         
            +
            	ULONG2NUM(startstack), ULONG2NUM(kstkesp), ULONG2NUM(kstkeip),
         
     | 
| 
      
 89 
     | 
    
         
            +
            	ULONG2NUM(signal), ULONG2NUM(blocked), ULONG2NUM(sigignore), ULONG2NUM(sigcatch),
         
     | 
| 
      
 90 
     | 
    
         
            +
            	ULONG2NUM(wchan), ULONG2NUM(nswap), ULONG2NUM(cnswap),
         
     | 
| 
      
 91 
     | 
    
         
            +
            	INT2NUM(exit_signal), INT2NUM(processor),
         
     | 
| 
      
 92 
     | 
    
         
            +
            	UINT2NUM(rt_priority), UINT2NUM(policy),
         
     | 
| 
      
 93 
     | 
    
         
            +
            	ULL2NUM(delayacct_blkio_ticks), ULONG2NUM(guest_time), LONG2NUM(cguest_time), ULONG2NUM(start_data),
         
     | 
| 
      
 94 
     | 
    
         
            +
            	ULONG2NUM(end_data), ULONG2NUM(start_brk), ULONG2NUM(arg_start), ULONG2NUM(arg_end),
         
     | 
| 
      
 95 
     | 
    
         
            +
            	ULONG2NUM(env_start), ULONG2NUM(env_end),
         
     | 
| 
      
 96 
     | 
    
         
            +
            	INT2NUM(exit_code)
         
     | 
| 
      
 97 
     | 
    
         
            +
            	) ;
         
     | 
| 
      
 98 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/procfs/statm.h
    ADDED
    
    | 
         @@ -0,0 +1,109 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #define PAGESIZE sysconf(_SC_PAGESIZE)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            VALUE statm(VALUE obj, VALUE pid) {
         
     | 
| 
      
 4 
     | 
    
         
            +
            	VALUE hash = rb_hash_new() ;
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 7 
     | 
    
         
            +
            	if (_pid < 0) return hash ;
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 10 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/statm", _pid) ;
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 13 
     | 
    
         
            +
            	if (!f) return hash ;
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            	unsigned int _virtual, resident, shared ;
         
     | 
| 
      
 16 
     | 
    
         
            +
            	char status = fscanf(f, "%u %u %u", &_virtual, &resident, &shared) ;
         
     | 
| 
      
 17 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            	if (status != 3) return hash ;
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            	int pagesize = PAGESIZE ;
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            	_virtual *= pagesize ;
         
     | 
| 
      
 24 
     | 
    
         
            +
            	resident *= pagesize ;
         
     | 
| 
      
 25 
     | 
    
         
            +
            	shared *= pagesize ;
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            	unsigned int v = resident - shared ;
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("memory")), UINT2NUM(v)) ;
         
     | 
| 
      
 30 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("virtual_memory")), UINT2NUM(_virtual)) ;
         
     | 
| 
      
 31 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("resident_memory")), UINT2NUM(resident)) ;
         
     | 
| 
      
 32 
     | 
    
         
            +
            	rb_hash_aset(hash, ID2SYM(rb_intern("shared_memory")), UINT2NUM(shared)) ;
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            	return hash ;
         
     | 
| 
      
 35 
     | 
    
         
            +
            }
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            VALUE statm_virtual(VALUE obj, VALUE pid) {
         
     | 
| 
      
 38 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 39 
     | 
    
         
            +
            	if (_pid < 0) return Qnil ;
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 42 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/statm", _pid) ;
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 45 
     | 
    
         
            +
            	if (!f) return Qnil ;
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            	unsigned int _virtual ;
         
     | 
| 
      
 48 
     | 
    
         
            +
            	char status = fscanf(f, "%u", &_virtual) ;
         
     | 
| 
      
 49 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            	if (status != 1) return Qnil ;
         
     | 
| 
      
 52 
     | 
    
         
            +
            	return UINT2NUM(_virtual * PAGESIZE) ;
         
     | 
| 
      
 53 
     | 
    
         
            +
            }
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            VALUE statm_resident(VALUE obj, VALUE pid) {
         
     | 
| 
      
 56 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 57 
     | 
    
         
            +
            	if (_pid < 0) return Qnil ;
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 60 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/statm", _pid) ;
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 63 
     | 
    
         
            +
            	if (!f) return Qnil ;
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
            	unsigned int resident ;
         
     | 
| 
      
 66 
     | 
    
         
            +
            	char status = fscanf(f, "%*u %u", &resident) ;
         
     | 
| 
      
 67 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
            	if (status != 1) return Qnil ;
         
     | 
| 
      
 70 
     | 
    
         
            +
            	return UINT2NUM(resident * PAGESIZE) ;
         
     | 
| 
      
 71 
     | 
    
         
            +
            }
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            VALUE statm_shared(VALUE obj, VALUE pid) {
         
     | 
| 
      
 74 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 75 
     | 
    
         
            +
            	if (_pid < 0) return Qnil ;
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 78 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/statm", _pid) ;
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 81 
     | 
    
         
            +
            	if (!f) return Qnil ;
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
            	unsigned int shared ;
         
     | 
| 
      
 84 
     | 
    
         
            +
            	char status = fscanf(f, "%*u %*u %u", &shared) ;
         
     | 
| 
      
 85 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            	if (status != 1) return Qnil ;
         
     | 
| 
      
 88 
     | 
    
         
            +
            	return UINT2NUM(shared * PAGESIZE) ;
         
     | 
| 
      
 89 
     | 
    
         
            +
            }
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
            VALUE statm_memory(VALUE obj, VALUE pid) {
         
     | 
| 
      
 92 
     | 
    
         
            +
            	int _pid = FIX2INT(pid) ;
         
     | 
| 
      
 93 
     | 
    
         
            +
            	if (_pid < 0) return Qnil ;
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            	char _path[22] ;
         
     | 
| 
      
 96 
     | 
    
         
            +
            	sprintf(_path, "/proc/%d/statm", _pid) ;
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            	FILE *f = fopen(_path, "r") ;
         
     | 
| 
      
 99 
     | 
    
         
            +
            	if (!f) return Qnil ;
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
            	unsigned int resident, shared ;
         
     | 
| 
      
 102 
     | 
    
         
            +
            	char status = fscanf(f, "%*u %u %u", &resident, &shared) ;
         
     | 
| 
      
 103 
     | 
    
         
            +
            	fclose(f) ;
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            	if (status != 2) return Qnil ;
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            	unsigned int v = (resident - shared) * PAGESIZE ;
         
     | 
| 
      
 108 
     | 
    
         
            +
            	return UINT2NUM(v) ;
         
     | 
| 
      
 109 
     | 
    
         
            +
            }
         
     | 
    
        data/ext/procfs/uptime.h
    ADDED
    
    
    
        data/ext/sysconf/extconf.rb
    CHANGED
    
    
    
        data/ext/sysconf/sysconf.c
    CHANGED
    
    | 
         @@ -12,7 +12,7 @@ 
     | 
|
| 
       12 
12 
     | 
    
         
             
            #endif
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            static VALUE getTick(VALUE obj) {
         
     | 
| 
       15 
     | 
    
         
            -
            	 
     | 
| 
      
 15 
     | 
    
         
            +
            	int val = sysconf(_SC_CLK_TCK) ;
         
     | 
| 
       16 
16 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
       18 
18 
     | 
    
         
             
            	return INT2FIX(val) ;
         
     | 
| 
         @@ -22,84 +22,84 @@ static VALUE getChildMax(VALUE obj) { 
     | 
|
| 
       22 
22 
     | 
    
         
             
            	long long int val = sysconf(_SC_CHILD_MAX) ;
         
     | 
| 
       23 
23 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
            	return  
     | 
| 
      
 25 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       26 
26 
     | 
    
         
             
            }
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
            static VALUE getHostnameMax(VALUE obj) {
         
     | 
| 
       29 
     | 
    
         
            -
            	 
     | 
| 
      
 29 
     | 
    
         
            +
            	long long val = sysconf(_SC_HOST_NAME_MAX) ;
         
     | 
| 
       30 
30 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
            	return  
     | 
| 
      
 32 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       33 
33 
     | 
    
         
             
            }
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            static VALUE getLoginNameMax(VALUE obj) {
         
     | 
| 
       36 
     | 
    
         
            -
            	 
     | 
| 
      
 36 
     | 
    
         
            +
            	long long val = sysconf(_SC_LOGIN_NAME_MAX) ;
         
     | 
| 
       37 
37 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       38 
38 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
            	return  
     | 
| 
      
 39 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       40 
40 
     | 
    
         
             
            }
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
            static VALUE getOpenMax(VALUE obj) {
         
     | 
| 
       43 
     | 
    
         
            -
            	 
     | 
| 
      
 43 
     | 
    
         
            +
            	long long val = sysconf(_SC_OPEN_MAX) ;
         
     | 
| 
       44 
44 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
            	return  
     | 
| 
      
 46 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       47 
47 
     | 
    
         
             
            }
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
            static VALUE getPageSize(VALUE obj) {
         
     | 
| 
       50 
     | 
    
         
            -
            	 
     | 
| 
      
 50 
     | 
    
         
            +
            	int val = sysconf(_SC_PAGESIZE) ;
         
     | 
| 
       51 
51 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       52 
52 
     | 
    
         | 
| 
       53 
53 
     | 
    
         
             
            	return INT2FIX(val) ;
         
     | 
| 
       54 
54 
     | 
    
         
             
            }
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
            static VALUE getStreamMax(VALUE obj) {
         
     | 
| 
       57 
     | 
    
         
            -
            	 
     | 
| 
      
 57 
     | 
    
         
            +
            	long long val = sysconf(_SC_STREAM_MAX) ;
         
     | 
| 
       58 
58 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       59 
59 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
            	return  
     | 
| 
      
 60 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       61 
61 
     | 
    
         
             
            }
         
     | 
| 
       62 
62 
     | 
    
         | 
| 
       63 
63 
     | 
    
         
             
            static VALUE getTTYNameMax(VALUE obj) {
         
     | 
| 
       64 
     | 
    
         
            -
            	 
     | 
| 
      
 64 
     | 
    
         
            +
            	long long val = sysconf(_SC_TTY_NAME_MAX) ;
         
     | 
| 
       65 
65 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
     | 
    
         
            -
            	return  
     | 
| 
      
 67 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       68 
68 
     | 
    
         
             
            }
         
     | 
| 
       69 
69 
     | 
    
         | 
| 
       70 
70 
     | 
    
         
             
            static VALUE getPosixVersion(VALUE obj) {
         
     | 
| 
       71 
     | 
    
         
            -
            	 
     | 
| 
      
 71 
     | 
    
         
            +
            	long long val = sysconf(_SC_VERSION) ;
         
     | 
| 
       72 
72 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       73 
73 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
            	return  
     | 
| 
      
 74 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       75 
75 
     | 
    
         
             
            }
         
     | 
| 
       76 
76 
     | 
    
         | 
| 
       77 
77 
     | 
    
         
             
            static VALUE getLineMax(VALUE obj) {
         
     | 
| 
       78 
     | 
    
         
            -
            	 
     | 
| 
      
 78 
     | 
    
         
            +
            	long long val = sysconf(_SC_LINE_MAX) ;
         
     | 
| 
       79 
79 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       80 
80 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
            	return  
     | 
| 
      
 81 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       82 
82 
     | 
    
         
             
            }
         
     | 
| 
       83 
83 
     | 
    
         | 
| 
       84 
84 
     | 
    
         
             
            static VALUE getExprNestMax(VALUE obj) {
         
     | 
| 
       85 
     | 
    
         
            -
            	 
     | 
| 
      
 85 
     | 
    
         
            +
            	long long val = sysconf(_SC_EXPR_NEST_MAX) ;
         
     | 
| 
       86 
86 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       87 
87 
     | 
    
         | 
| 
       88 
     | 
    
         
            -
            	return  
     | 
| 
      
 88 
     | 
    
         
            +
            	return LL2NUM(val) ;
         
     | 
| 
       89 
89 
     | 
    
         
             
            }
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
91 
     | 
    
         
             
            static VALUE getProcessorConfigured(VALUE obj) {
         
     | 
| 
       92 
     | 
    
         
            -
            	 
     | 
| 
      
 92 
     | 
    
         
            +
            	long val = sysconf(_SC_NPROCESSORS_CONF) ;
         
     | 
| 
       93 
93 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       94 
94 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
            	return  
     | 
| 
      
 95 
     | 
    
         
            +
            	return LONG2NUM(val) ;
         
     | 
| 
       96 
96 
     | 
    
         
             
            }
         
     | 
| 
       97 
97 
     | 
    
         | 
| 
       98 
98 
     | 
    
         
             
            static VALUE getProcessorOnline(VALUE obj) {
         
     | 
| 
       99 
     | 
    
         
            -
            	 
     | 
| 
      
 99 
     | 
    
         
            +
            	long val = sysconf(_SC_NPROCESSORS_ONLN) ;
         
     | 
| 
       100 
100 
     | 
    
         
             
            	if (val < 0) return Qnil ;
         
     | 
| 
       101 
101 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
            	return  
     | 
| 
      
 102 
     | 
    
         
            +
            	return LONG2NUM(val) ;
         
     | 
| 
       103 
103 
     | 
    
         
             
            }
         
     | 
| 
       104 
104 
     | 
    
         | 
| 
       105 
105 
     | 
    
         
             
            static VALUE getUser(VALUE obj) {
         
     | 
| 
         @@ -108,22 +108,22 @@ static VALUE getUser(VALUE obj) { 
     | 
|
| 
       108 
108 
     | 
    
         
             
            }
         
     | 
| 
       109 
109 
     | 
    
         | 
| 
       110 
110 
     | 
    
         
             
            static VALUE getUID(VALUE obj) {
         
     | 
| 
       111 
     | 
    
         
            -
            	return  
     | 
| 
      
 111 
     | 
    
         
            +
            	return UINT2NUM((unsigned int) getuid()) ;
         
     | 
| 
       112 
112 
     | 
    
         
             
            }
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
            static VALUE getGID(VALUE obj) {
         
     | 
| 
       115 
     | 
    
         
            -
            	return  
     | 
| 
      
 115 
     | 
    
         
            +
            	return UINT2NUM((unsigned int) getgid()) ;
         
     | 
| 
       116 
116 
     | 
    
         
             
            }
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
            static VALUE getEUID(VALUE obj) {
         
     | 
| 
       119 
     | 
    
         
            -
            	return  
     | 
| 
      
 119 
     | 
    
         
            +
            	return UINT2NUM((unsigned int) geteuid()) ;
         
     | 
| 
       120 
120 
     | 
    
         
             
            }
         
     | 
| 
       121 
121 
     | 
    
         | 
| 
       122 
122 
     | 
    
         
             
            static VALUE getHostname(VALUE obj) {
         
     | 
| 
       123 
123 
     | 
    
         
             
            	int h_max = sysconf(_SC_HOST_NAME_MAX) + 1 ;
         
     | 
| 
       124 
124 
     | 
    
         
             
            	char hostname[h_max] ;
         
     | 
| 
       125 
125 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
            	 
     | 
| 
      
 126 
     | 
    
         
            +
            	char status = gethostname(hostname, h_max) ;
         
     | 
| 
       127 
127 
     | 
    
         | 
| 
       128 
128 
     | 
    
         
             
            	return (status < 0) ? rb_str_new_cstr("") : rb_str_new_cstr(hostname) ;
         
     | 
| 
       129 
129 
     | 
    
         
             
            }
         
     |