Jump to content

DosQuerySysState: Difference between revisions

From EDM2
Ak120 (talk | contribs)
merge
Ak120 (talk | contribs)
 
Line 90: Line 90:
===Example Code===
===Example Code===
<PRE>
<PRE>
#define BUFSIZE 64*1024int main(int argc, char *argv[], char *envp[])
#define BUFSIZE 64*1024
 
int main(int argc, char *argv[], char *envp[])
{
{
   APIRET rc;
   APIRET rc;
Line 96: Line 98:
   qsGrec_t * pGrec;
   qsGrec_t * pGrec;
   qsLrec_t * pLrec;
   qsLrec_t * pLrec;


   pBuf=malloc(BUFSIZE); /* allocate a 64K buffer */
   pBuf=malloc(BUFSIZE); /* allocate a 64K buffer */

Latest revision as of 11:43, 23 August 2018

DosQuerySysState returns information about various resources in use by the system. The EntityList parameter determines which information is returned according to the bits set in this parameter.

Syntax

APIRET APIENTRY DosQuerySysState (ULONG EntityList, ULONG EntityLevel,
                                  PID pid, TID tid, PVOID pDataBuf, ULONG cbBuf);

Parameters

EntityList (ULONG) input
Determines what information is returned. May be a combination of the following:
QS_PROCESS   0x0001 Requests process information
QS_SEMAPHORE 0x0002 Requests semaphore information
QS_MTE       0x0004 Requests module information
QS_FILESYS   0x0008 Requests file system information
QS_SHMEMORY  0x0010 Requests shared memory information
QS_MODVER    0x0200 Requests module version information
EntityLevel (ULONG) input
Determines the extent of information returned for a given entity. This applies to QS_MTE entities only. If EntityLevel is also set to SQ_MTE, then module object information is returned.
pid (PID) input
Restricts information to a particular process ID. If 0 is specified, then entities for all processes are returned.
tid (TID) input
Restricts information to a particular thread ID. A value of zero only is supported, requesting all threads of a process.
pDataBuf (PVOID) output
Pointer to the buffer allocated by the user into which entity structures are returned. If the buffer is of insufficient size, then an ERROR_BUFFER_OVERFLOW is returned.
cbBuf (ULONG) input
Size of the buffer pointed to by pDataBuf in bytes.
Parameters
ULONG func
Bit flag indicating which data is being requested.
ULONG arg1
Reserved. Set to zero always.
ULONG pid
Process ID. See notes.
ULONG _res_
Reserved.
ULONG buf
Address of buffer for results. See DOSQSS.H for the layout.
ULONG bufsz:Size of result buffer.

Return Code

ulrc (APIRET) returns
DosQuerySysState returns one of the following values
  • 0 NO_ERROR
  • 87 ERROR_INVALID_PARAMETER
  • 111 ERROR_BUFFER_OVERFLOW
  • 115 ERROR_PROTECTION_VIOLATION
  • 124 ERROR_INVALID_LEVEL

Linkage Definition

IMPORTS Dos32QuerySysState = DOSCALLS.368 

Remarks

The information returned by DosQuerySysState begins with a pointer to the global record structure, qsGrec_s. Following this will be a series of other records which depend on what information was requested. Some of these subsequent record structures contain an identifier as their first member, which enables the returned information to be interpreted without any order being imposed.

Entities that may be requested are:

Process information QS_PROCESS
Semaphore information QS_SEMAPHORE
Module information QS_MTE
File system information QS_FILESYS
Shared memory information QS_SHMEMORY
Module Version information QS_MODVER

Not all entities have been supported in earlier versions of OS/2.

The structures returned will be a combination of the following:

qsGrec_t Global Record structure
qsTrec_t Thread Record structure
qsPrec_t Process Record structure
qsS16rec_t 16 bit system semaphore structure
qsS16Headrec_t 16 bit system semaphore structure
qsMrec_t Shared Memory Record structure
QSOPENQ 32 bit Open Semaphore structure
QSEVENT 32 bit Event Semaphore structure
QSMUTEX 32 bit Mutex semaphore structure
QSMUX 32 bit Mux semaphore structure
QSHUN 32 bit semaphore header structure
qsS32rec_t - 32 bit semaphore header structure
qsLObjrec_t - Object level MTE information
qsLrec_t - System wide MTE information
qsExLrec_t - Module version information
qsSft_t - System wide FILE information one per open instance
qsFrec_t - System wide FILE information one per file name
qsPtrRec_t - System wide FILE information

Comments

This function performs almost exactly the same function as the older DosQProcStat, except that the 64K limit on buffer size has been removed, all addresses are in 0:32 format, and some more information has been added.

The func parameter is a bit array, with the following meanings:

00000001 Process Data
00000002 Process Semaphores (16-bit only?)
00000004 Module Data
00000008 File Data (see notes)
00000010 Named Shared Memory

Notes:

  1. The pid parameter allows you to request information for a single process (if non-zero), or for all processes on the system. NOTE: Selection of a single process caused system hangs prior to Warp 3.0 Fixpack 18.
  2. The arg1 parameter must be set to zero, or it may cause a system crash. IBM has reported this problem fixed in APAR PJ21195.
  3. File data is only supported from Warp 3.0 Fixpack 18 onwards.

Examples

Example Code

#define BUFSIZE 64*1024

int main(int argc, char *argv[], char *envp[])
{
   APIRET rc;
   qsGrec_t ** pBuf;
   qsGrec_t * pGrec;
   qsLrec_t * pLrec;

   pBuf=malloc(BUFSIZE); /* allocate a 64K buffer */
   if (pBuf == NULL) {
      printf("Not enough memoryan");
      return ERROR_NOT_ENOUGH_MEMORY;
   } /* endif */

   /* query module information */

   rc=DosQuerySysState(QS_MTE, 0L, 0L, 0L, pBuf, BUFSIZE);
   if (rc!=0) {
      printf("DosQuerySysState returned rc=%u\n",rc);
      return rc;
   } /* endif */

   pGrec = *  pBuf;

   printf("Threads=%u 32-bit Sems=%u File Names=%u\n\n",
                pGrec->cThrds,
                pGrec->c32SSem,
                pGrec->cMFTNodes);

   pLrec = (ULONG)pGrec + sizeof(qsGrec_t);

   while (pLrec) {
      if (pLrec->pName) printf("hmte=%04x %s\n", pLrec->hmte, pLrec->pName);
      pLrec = pLrec->pNextRec;
   } /* endwhile */

   return rc;
}

Related Functions