From:	SMTP%"RELAY-INFO-VAX@CRVAX.SRI.COM"  9-APR-1994 10:12:11.85
To:	EVERHART
CC:	
Subj:	Re: Count free channels in a program

Date: Fri, 08 Apr 1994 14:32:23 +0100
From: Arne Vajhoej <ARNE@kopc.hhs.dk>
Subject: Re: Count free channels in a program
To: ARVIDSSONA@ADMINA.RFERL.ORG, INFO-VAX@SRI.COM
Message-Id: <01HAXOXYBAQA8WW1I6@kopc.hhs.dk>
X-Vms-To: KOPC::IN%"ARVIDSSONA@ADMINA.RFERL.ORG"
X-Vms-Cc: IN::"INFO-VAX@SRI.COM"
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-1
Content-Transfer-Encoding: 8BIT

> I wonder if anyone have a program or idea how to check how many free
> channels a process has left.

The following small programs does it:

#include <stdio.h>
#include "ccbdef.h"

globalref short sgn$gw_pchancnt;
globalref long ctl$gl_ccbbase;

main()
{
   int i,n,chan;
   struct ccbdef *p;
   n = sgn$gw_pchancnt;
   p = (struct ccbdef *) ctl$gl_ccbbase;
   chan = 0;
   for(i=0;i<n;i++) {
      if (p->ccb$b_amod!=0) chan++;
      p--;
   }
   printf("used channels = %d\n",chan);
   printf("available channels = %d\n",n-chan);
}

OK ?

Notes:
  - remember to link with SYS.STB
  - CCBDEF.H is attached below
  - it do not work on AXP (can not find CTL$GL_CCBBASE)

                                                          Arne

Arne Vajhxj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK

================================================================================

/* <ccbdef.h>
 *
 *	Channel control block definitions (not available from Starlet).
 */
#ifndef _CCBDEF_H
#define _CCBDEF_H

#define CCB$V_AMB	0
#define CCB$V_IMGTMP	1
#define CCB$V_RDCHKDON	2
#define CCB$V_WRTCHKDON 3
#define CCB$V_LOGCHKDON 4
#define CCB$V_PHYCHKDON 5
#define CCB$M_AMB	(1<<CCB$V_AMB)		/* 0x01 */
#define CCB$M_IMGTMP	(1<<CCB$V_IMGTMP)	/* 0x02 */
#define CCB$M_RDCHKDON	(1<<CCB$V_RDCHKDON)	/* 0x04 */
#define CCB$M_WRTCHKDON (1<<CCB$V_WRTCHKDON)	/* 0x08 */
#define CCB$M_LOGCHKDON (1<<CCB$V_LOGCHKDON)	/* 0x10 */
#define CCB$M_PHYCHKDON (1<<CCB$V_PHYCHKDON)	/* 0x20 */

struct ccbdef {
    long	    ccb$l_ucb;
    long	    ccb$l_wind;
    unsigned char   ccb$b_sts;
    unsigned char   ccb$b_amod;
    unsigned short  ccb$w_ioc;
    long	    ccb$l_dirp;
};
#endif	/*_CCBDEF_H*/

