| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | process list |
Hello Paul!
PE> PSTAT prints a list of processes in the system. How do I do the same
PE> thing from my C program? (besides system("pstat")!). I
have looked
PE> at GUIREF20 and can't find a suitable API (I want all system
PE> processes, not just ones that I spawned).
Find info on DosQProcStatus, PSTAT uses it. Or maybe this helps:
-------------------------------8<------------------------------------
Ä OS2PROG (2:5020/620) ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ OS2PROG Ä
Msg : 825 of 1824 Rcv Scn
From : Thomas Seeling 2:244/1130.42 Fri 16 Feb 96 20:54
To : Rinat Sadretdinow Fri 23 Feb 96 22:01
Subj : detecting a process
ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
Hallo, Rinat!
*** Am Dienstag 13. Februar 1996 um 13:30 schrieb Rinat Sadretdinow an Phil
Crown:
RS> Try to use DosQProcStatus and then scan over the info returned.
=== Cut ===
MD> Frin; veit{at}urk.gmd.de (Holger Veit)
MD> Newsgroups: comp.os.os2.programmer.misc
MD>
MD> Subject: Re: DosQProcStatus Date: 20 Jan 1996 10:38:39
: : |>> Can anyone point me towards some documentation on DosQProcStatus?
: : |>>
: : |>> I know it's and "undocumented" API but somebody
must know how to
: : |>> use it. Thanks, Travis.
MD> :
MD> : : You don't want to use the 16 bit DosQProcStatus function any
MD> longer nowadays, : : take the 32 bit equivalent DosQuerySysState. : :
MD>
MD> See http://borneo.gmd.de/~veit/os2/sysstate.doc.html on that. : : Is
MD> there any other source of information on that (such as sample usage).
MD>
MD> : I tried to use it without much luck - I keep getting 87 (invalid
MD> parameters) : and 111 (buffer size not large enough) error codes,
MD> even
MD> with the exact same : call. I've been looking for quite some time
MD> for
MD> this new API function; now : that it's here, I want to use it!
MD> You get error 87 if you provide an incorrect first argument of zero.
MD> You get error 111 if your buffer is too small or the buffer size
MD> argument is incorrect. Expect a 64K buffer as sufficient.
MD> Try this one (tested with EMX0.9B: gcc -o dosq.exe dosq.c dosq.def).
MD> Three files following.
MD> Maybe someone should put this into the programmer's FAQ.
MD> =========dosq.c==================
MD> #include
MD> #include
MD> #include
MD> #include
MD> #include "dosqss.h"
MD> extern APIRET DosQuerySysState (ULONG func,
MD> ULONG par1, ULONG pid, ULONG _reserved_,
MD> PCHAR buf,
MD> ULONG bufsz);
MD> static void dump_global(PQTOPLEVEL);
MD> static void dump_process(PQTOPLEVEL);
MD> static void dump_sema(PQTOPLEVEL);
MD> static void dump_shrmem(PQTOPLEVEL);
MD> static void dump_module(PQTOPLEVEL);
MD> main(void)
MD> {
MD> int i;
MD> APIRET rc;
MD> #define BUFSIZE 64000
MD> #define RESERVED 0
MD> char *buf = malloc(BUFSIZE);
MD> rc = DosQuerySysState(0x1f, RESERVED, RESERVED, RESERVED,
MD> (PCHAR)buf, BUFSIZE);
MD> if (!rc) {
MD> PQTOPLEVEL top = (PQTOPLEVEL)buf;
MD> dump_global(top);
MD> dump_process(top);
MD> dump_module(top);
MD> dump_sema(top);
MD> dump_shrmem(top);
MD> }
MD> }
MD> static void dump_global(PQTOPLEVEL top)
MD> {
MD> PQGLOBAL g = top->gbldata;
MD> printf("Global section:\n");
MD> printf("\t# of processes: %d\n",g->proccnt);
MD> printf("\t# of threads: %d\n",g->threadcnt);
MD> printf("\t# of modules: %d\n\n",g->modulecnt);
MD> }
MD> static void dump_process(PQTOPLEVEL top)
MD> {
MD> PQPROCESS p = top->procdata;
MD> PQTHREAD t;
MD> int i;
MD> printf("Process section:\n");
MD> while (p->rectype != 3) {
MD> printf("\n PID: %d\n",p->pid);
MD> printf("\tPPID: %d\n",p->ppid);
MD> printf("\ttype: %x\n",p->type);
MD> printf("\tstate: %x\n",p->state);
MD> printf("\tsession id: %d\n",p->sessid);
MD> printf("\tmod handle: %x\n",p->hndmod);
MD> printf("\t# of threads: %d\n",p->threadcnt);
MD> t = p->threads;
MD> for (i=0; ithreadcnt; i++,t++) {
MD> printf("\t TID: %d\n",t->threadid);
MD> printf("\t\tslot: %x\n",t->slotid);
MD> printf("\t\tsleepid: %x\n",t->sleepid);
MD> printf("\t\tpriority: %x\n",t->priority);
MD> printf("\t\tsystime: %d\n",t->systime);
MD> printf("\t\tusertime: %d\n",t->usertime);
MD> printf("\t\tstate: %d\n",t->state);
MD> }
MD> printf("\t# of 16 bit sema: %d\n",p->sem16cnt);
MD> if (p->sem16cnt) {
MD> printf("\t\t");
MD> for (i=0; isem16cnt; i++)
MD> printf("%04X ",p->sem16s[i]);
MD> printf("\n");
MD> }
MD> printf("\t# of dlls: %d\n",p->dllcnt);
MD> if (p->dllcnt) {
MD> printf("\t\t");
MD> for (i=0; idllcnt; i++)
MD> printf("%04X ",p->dlls[i]);
MD> printf("\n");
MD> }
MD> printf("\t# of shrmem: %d\n",p->shrmemcnt);
MD> if (p->shrmemcnt) {
MD> printf("\t\t");
MD> for (i=0; ishrmemcnt; i++)
MD> printf("%04X ",p->shrmems[i]);
MD> printf("\n");
MD> }
MD> p = (PQPROCESS)t;
MD> }
MD> }
MD> static void dump_module(PQTOPLEVEL top)
MD> {
MD> PQMODULE m = top->moddata;
MD> int i;
MD> printf("Module section:\n");
MD> while (m) {
MD> printf("\thandle: %x\n",m->hndmod);
MD> printf("\ttype: %d\n",m->type);
MD> printf("\treference count: %d\n",m->refcnt);
MD> if (m->refcnt) {
MD> printf("\t\t");
MD> for (i=0; irefcnt; i++) {
MD> printf("%04X ",m->modref[i]);
MD> }
MD> printf("\n");
MD> }
MD> printf("\tsegment count: %d\n",m->segcnt);
MD> printf("\tname: %s\n",m->name);
MD> m = m->next;
MD> }
MD> }
MD> static void dump_sema(PQTOPLEVEL top)
MD> {
MD> PQSEMSTRUC s = top->semadata;
MD> PQSEMA p = &s->sema;
MD> int i;
MD> printf("Semaphore section:\n");
MD> printf("\tsema 16 index: %x\n\n",s->index);
MD> while (p) {
MD> printf("\treference count: %d\n",p->refcnt);
MD> printf("\tflags: %x\n",p->sysflags);
MD> printf("\tproc count: %x\n",p->sysproccnt);
MD> printf("\tindex: %x\n",p->index);
MD> printf("\tname: %s\n",p->name);
MD> p = p->next;
MD> }
MD> }
MD> static void dump_shrmem(PQTOPLEVEL top)
MD> {
MD> PQSHRMEM s = top->shrmemdata;
MD> int i;
MD> printf("Shared Memory section:\n");
MD> while (s) {
MD> printf("\n handle: %x\n",s->hndshr);
MD> printf("\tselector: %d\n",s->selshr);
MD> printf("\treference count: %d\n",s->refcnt);
MD> printf("\tname: %s\n",s->name);
MD> s = s->next;
MD> }
MD> }
MD> =========--dosqss.h===============--
MD> #ifndef DOSQSS_H
MD> #define DOSQSS_H
MD> typedef struct {
MD> ULONG threadcnt;
MD> ULONG proccnt;
MD> ULONG modulecnt;
MD> } QGLOBAL, *PQGLOBAL;
MD> typedef struct {
MD> ULONG rectype;
MD> USHORT threadid;
MD> USHORT slotid;
MD> ULONG sleepid;
MD> ULONG priority;
MD> ULONG systime;
MD> ULONG usertime;
MD> UCHAR state;
MD> } QTHREAD, *PQTHREAD;
MD> typedef struct {
MD> USHORT n1;
MD> USHORT n2;
MD> USHORT n3;
MD> USHORT n4;
MD> USHORT n5;
MD> USHORT n6;
MD> ULONG filesize;
MD> USHORT n7;
MD> USHORT n8;
MD> USHORT _reserved_;
MD> } QFDS, *PQFDS;
MD> typedef struct qfile {
MD> ULONG rectype;
MD> struct qfile *next;
MD> ULONG opencnt;
MD> PQFDS filedata;
MD> char name[1];
MD> } QFILE, *PQFILE;
MD> typedef struct {
MD> ULONG rectype;
MD> PQTHREAD threads;
MD> USHORT pid;
MD> USHORT ppid;
MD> ULONG type;
MD> ULONG state;
MD> ULONG sessid;
MD> USHORT hndmod;
MD> USHORT threadcnt;
MD> ULONG _reserved1_;
MD> ULONG _reserved2_;
MD> USHORT sem16cnt;
MD> USHORT dllcnt;
MD> USHORT shrmemcnt;
MD> USHORT fdscnt;
MD> PUSHORT sem16s;
MD> PUSHORT dlls;
MD> PUSHORT shrmems;
MD> PUSHORT fds;
MD> } QPROCESS, *PQPROCESS;
MD> typedef struct sema {
MD> struct sema *next;
MD> USHORT refcnt;
MD> UCHAR sysflags;
MD> UCHAR sysproccnt;
MD> ULONG _reserved1_;
MD> USHORT index;
MD> CHAR name[1];
MD> } QSEMA, *PQSEMA;
MD> typedef struct {
MD> ULONG rectype;
MD> ULONG _reserved1_;
MD> ULONG _reserved2_;
MD> ULONG index;
MD> QSEMA sema;
MD> } QSEMSTRUC, *PQSEMSTRUC;
MD> typedef struct shrmem {
MD> struct shrmem *next;
MD> USHORT hndshr;
MD> USHORT selshr;
MD> USHORT refcnt;
MD> CHAR name[1];
MD> } QSHRMEM, *PQSHRMEM;
MD> typedef struct module {
MD> struct module *next;
MD> USHORT hndmod;
MD> USHORT type;
MD> ULONG refcnt;
MD> ULONG segcnt;
MD> PVOID _reserved_;
MD> PCHAR name;
MD> USHORT modref[1];
MD> } QMODULE, *PQMODULE;
MD> typedef struct {
MD> PQGLOBAL gbldata;
MD> PQPROCESS procdata;
MD> PQSEMSTRUC semadata;
MD> PVOID _reserved1_;
MD> PQSHRMEM shrmemdata;
MD> PQMODULE moddata;
MD> PVOID _reserved2_;
MD> PQFILE filedata;
MD> } QTOPLEVEL, *PQTOPLEVEL;
MD> #endif
MD> ======--dosq.def============
MD> NAME DOSQEXAM WINDOWCOMPAT
MD> DESCRIPTION "Sample program to illustrate DosQuerySysState"
MD> PROTMODE
MD> EXETYPE OS2
MD> IMPORTS
MD> _DosQuerySysState = DOSCALLS.168
MD> ======--end of code=========
MD> Dr.-Ing. Holger Veit | INTERNET:
MD> Holger.Veit{at}gmd.de | | / GMD - German National Research | Phone:
MD>
MD> (+49) 2241 14 2448 |__| / Center for Information Technology| Fax:
MD>
MD> (+49) 2241 14 2242 | | / Schloss Birlinghoven |
MD> "They're not sending back [Win95] | |/ D-53754 Sankt Augustin,
MD> Germany | because it's not selling well; they WWW:
MD> http://borneo.gmd.de/~veit/ | have overordered" (M$ spokesperson)
MD> --
=== Cut ===
Tschau...Thomas
--- E3-32/1.11-32/2.50+
* Origin: Die TeX-Box +49-6034-1455 V.34 -930022 ISDN 24h (2:244/1130.42)SEEN-BY: 50/99 270/101 620/243 625/160 711/401 409 410 413 430 808 809 934 SEEN-BY: 711/955 712/407 515 624 628 713/317 800/1 @PATH: 5020/620 509 443 79 5100/8 396/1 270/101 712/515 711/808 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.