From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM"  9-APR-1994 13:33:56.62
To:	EVERHART
CC:	
Subj:	RE: Count free channels in a program

From: gleason@mwk.com
X-Newsgroups: comp.os.vms
Subject: RE: Count free channels in a program
Message-Id: <1994Apr8.085551.1943@mwk.com>
Date: 8 Apr 94 08:55:51 CST
Organization: M. W. Kellogg, Houston TX
Lines: 94
To: Info-VAX@CRVAX.SRI.COM
X-Gateway-Source-Info: USENET

In article <9404080354.AA22580@uu3.psi.com>, Jerry Leichter <leichter@lrw.com> writes:
> 	I wonder if anyone have a program or idea how to check how many free 
> 	channels a process has left.  
> 
> The most direct measure is the FILCNT value, which you can get with
> $GETJPI.  (However, I think this value can be larger than the CHANNELCNT
> SYSGEN parameter, in which case that parameter establishes the true limit.)
> 
  Hey, channels are opened on things other than files...on the 
chance that this guy is really interested in the number of channels
left, rather than how many more files he can open, I'll commit the
hideous faux pas of posting a piece of code to comp.os.vms...

	.title	frechn
	.ident	'X01-000'
;+
;
; Facility:	Checking free channels
;
; Abstract:
;	This utility counts the number of free channels left to a process.
;
; Author:
;	Lee K. Gleason N5ZMR	(the fragmentation guy)
;	Control-G Consultants	(Will change mode to kernel for food)
;	1734 Wakefield
;	Houston TX 77018
;	Phone 713/681-3985
;	gleason@mwk.com
;
; Date:	8-APR-1994
;-

;+
;  FRECHN is a program cut from another program just to count free
;  channel blocks. FRECHN has more annoying commentary than actual code.
;	to use...
;	$ mac frechn
;	$ link frechn
;	$ run frechn
;
;-

	.library	"sys$library:lib.mlb"
	.link		"sys$system:sys.stb"/SELECTIVE_SEARCH

	$ccbdef		;channel block offsets 

        .psect  fcpur pic,quad,usr,con,rel,gbl,shr,noexe,rd,nowrt,novec

faostr:	.ascid	/Free channels = !UL/

        .psect  fcdat pic,long,usr,con,rel,gbl,noshr,noexe,rd,wrt,novec

total:	.long	0
outstr:	.long	64
	.long	.+4
	.blkb	64

        .psect  fccod pic,long,usr,con,rel,gbl,shr,exe,rd,nowrt,novec

;+
;  the ccb's in a process turn out to be readable from user mode
;  so no change mode (or actual danger) is involved. If you were
;  a real soldier, you could do this in DCL.
;-

	.entry	frechn,^m<r7,r8>

	movl	@#ctl$gl_ccbbase,r7	;base of CCBs to r7
	movzwl  @#ctl$gl_vectors,r8	;number of CCBs defined to r8

next:	subl	#ccb$k_length,r7	;back up one ccb
	decl	r8			;and decrement count
	bleq	end
 20$:	tstl	ccb$b_amod(r7)		;see if this ccb is in use
	bneq	next			;if not, go on to next one
	incl	total			;found one
	brb	next			;and go look at another

end:	

	$fao_s	ctrstr = faostr,- 
		outbuf = outstr,-
		outlen = outstr,-
		p1     = total

	pushal	outstr
	calls	#1,g^lib$put_output

	$exit_s

	.end	frechn


