Skip to main content

For jBASE users > 5.7, here's a sample class that can get additional information on a port (e.g. the port number and program that is locking another port).

Usage:

analyze = new object('$analyze')
details = analyze->fetch(port_nbr) ;! you can also do analyze->fetch(pid, @true)

if details->$hasproperty('blocking') then
    crt port_nbr:\\ is blocked by port \\:details->blocking->port:\\ at \\:details->blocking->location
end


analyze.jabba

 ! $analyze class
 
     method $analyze::$analyze()
 !
 ! $system is used to get stats on the port
 !
         this->o.sys = new object('$system')
 !
 ! Get the lock details for the port
 !
         this->o.lock = new object('$lock')
 !
 ! Open the proc dir needed for "call_stack"
 !
         proc_dir = system(1027)
         open proc_dir to proc then
             this->proc = proc
         end else
             throw \\Cannot open \\:proc_dir
         end
     end method
 
     method $analyze::fetch()
         arg = new object('$vararg')
         port_based = @true
         if (arg->size()) then
             port_nbr = arg->next()
             if (arg->size()) then
                 port_based = arg->next()
             end
         end else
             port_nbr = system(101)
         end
 !
 ! PID based?
 !
         if not(port_based) then
             rc = this->o.sys->getuserinfo()
             found_port = @false
             for user_info in this->o.sys->user
                 if user_info->pid eq port_nbr then
                     port_nbr = user_info->port_number
                     found_port = @true
                     break
                 end
             next
             if not(found_port) then
                 throw port_nbr:\\ is not a valid PID/jBASE process.\\
             end
         end
 
         result = new object()
 !
 ! Get the process details on the port
 !
         rc = this->o.sys->getuserinfo(port_nbr, @true)
         portinfo = this->o.sys->user->@port_nbr
         result->portinfo = portinfo
         proc = this->proc
         readv call_stack from proc,port_nbr,43 then
             result->call_stack = call_stack
         end
         result->locks = this->o.lock->getjdls(port_nbr, 1)
 !
 ! Is this port currently blocked on a lock?
 !
         if len(portinfo->locked_filename) then
             all_locks = this->o.lock->getjdls()
             found_port = @false
             for lock_info in all_locks
                 if portinfo->locked_filename eq lock_info->filepath and portinfo->locked_itemid eq lock_info->key then
                     blocking = new object()
                     blocking->port = lock_info->portno
                     blocking->location = lock_info->source_name
                     readv call_stack from proc,blocking->port,43 then
                         blocking->call_stack = call_stack
                     end
                     result->blocking = blocking
                     break
                 end
             next
         end
 
         return result
     end method


------------------------------
Peter Falson
Rocket Internal - All Brands
------------------------------