Changeset 420


Ignore:
Timestamp:
Dec 8, 2014, 3:25:53 AM (11 years ago)
Author:
pr
Message:

Add prc32KillProcessTree.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/include/helpers/procstat.h

    r206 r420  
    1313
    1414/*
    15  *      This file Copyright (C) 1992-99 Ulrich M”ller,
    16  *                                      Kai Uwe Rommel.
     15 *      This file Copyright (C) 1992-2014 Ulrich M”ller,
     16 *                                        Kai Uwe Rommel.
    1717 *      This file is part of the "XWorkplace helpers" source package.
    1818 *      This is free software; you can redistribute it and/or modify
     
    234234
    235235    // #pragma pack(1)
    236     #pragma pack(4)         // V0.9.10 (2001-04-08) [umoeller]
    237236
    238237    #define QS32_PROCESS      0x0001
     
    276275    {
    277276        ULONG   ulThreadCount;  // thread count
    278         ULONG   ulProcCount;    // process count
     277        // ULONG   ulProcCount;    // process count wrong V1.0.1 (2003-01-10) [umoeller]
     278        ULONG   ulSem32Count;   // count of 32-bit sems?
    279279        ULONG   ulModuleCount;  // module count
    280280    } QGLOBAL32, *PQGLOBAL32;
     
    806806     ********************************************************************/
    807807
     808    PQTOPLEVEL32 prc32GetInfo2(ULONG fl,
     809                               APIRET *parc);
     810
    808811    PQTOPLEVEL32 prc32GetInfo(APIRET *parc);
    809812
     
    830833    PQFILEDATA32 prc32FindFileData(PQTOPLEVEL32 pInfo,
    831834                                   USHORT usFileID);
     835
     836    void prc32KillProcessTree(ULONG pid);
     837
     838    void prc32KillProcessTree2(PQPROCESS32 pProcThis, ULONG pid);
    832839
    833840#endif
  • branches/branch-1-0/src/helpers/procstat.c

    r229 r420  
    3333/*
    3434 *      Copyright (C) 1992-1994 Kai Uwe Rommel.
    35  *      Copyright (C) 1998-2000 Ulrich M”ller.
     35 *      Copyright (C) 1998-2014 Ulrich M”ller.
    3636 *      This file is part of the "XWorkplace helpers" source package.
    3737 *      This is free software; you can redistribute it and/or modify
     
    5252#define INCL_DOSMODULEMGR
    5353#define INCL_DOSERRORS
     54#define INCL_DOSPROCESS
    5455#include <os2.h>
    5556
     
    9495
    9596    if (!ppps)
    96         return (ERROR_INVALID_PARAMETER);
     97        return ERROR_INVALID_PARAMETER;
    9798
    9899    // changed allocation V0.9.10 (2001-04-08) [umoeller]:
     
    187188    }
    188189
    189     return (pReturn);
     190    return pReturn;
    190191}
    191192
     
    222223    }
    223224
    224     return (pReturn);
     225    return pReturn;
    225226}
    226227
     
    300301    }
    301302
    302     return (rc);
     303    return rc;
    303304}
    304305
     
    349350    }
    350351
    351     return (ulrc);
     352    return ulrc;
    352353}
    353354
     
    394395    }
    395396
    396     return (ulrc);
     397    return ulrc;
    397398}
    398399
     
    483484    if (prc16QueryThreadInfo(pps, usPID, usTID, &prct))
    484485        ulrc = prct.ulPriority;
    485     return (ulrc);
     486    return ulrc;
    486487}
    487488
     
    497498
    498499/*
     500 *@@ prc32GetInfo2:
     501 *      nifty interface to DosQuerySysState, the 32-bit
     502 *      version of DosQProcStat.
     503 *
     504 *      This returns the head of a newly allocated buffer
     505 *      which has plenty of pointers for subsequent browing.
     506 *
     507 *      As opposed to prc32GetInfo, with this call you can
     508 *      specify the information that would like to retrieve.
     509 *
     510 *      Use prc32FreeInfo to free the buffer.
     511 *
     512 *@@added V1.0.1 (2003-01-10) [umoeller]
     513 */
     514
     515PQTOPLEVEL32 prc32GetInfo2(ULONG fl,        // in: QS32_* flags
     516                           APIRET *parc)    // out: error, ptr can be NULL
     517{
     518    APIRET          arc;
     519    PQTOPLEVEL32    pReturn = NULL;
     520
     521    #define BUFSIZE (1024 * 1024) // 1 meg
     522
     523    if (!(arc = DosAllocMem((PVOID*)&pReturn,
     524                            BUFSIZE,
     525                            PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE)))
     526    {
     527        if (arc = DosQuerySysState(fl,
     528                                   fl,      // this was missing V0.9.10 (2001-04-08) [umoeller]
     529                                   0, 0,
     530                                   (PCHAR)pReturn,
     531                                   BUFSIZE))
     532        {
     533            DosFreeMem(pReturn);
     534            pReturn = NULL;
     535        }
     536    }
     537
     538    if (parc)
     539        *parc = arc;
     540
     541    return pReturn;
     542}
     543
     544/*
    499545 *@@ prc32GetInfo:
    500  *      nifty interface to DosQuerySysState,
    501  *      the 32-bit version of DosQProcStat.
    502  *      This returns the head of a newly
    503  *      allocated buffer which has plenty
    504  *      of pointers for subsequent browing.
     546 *      nifty interface to DosQuerySysState, the 32-bit
     547 *      version of DosQProcStat.
     548 *
     549 *      This returns the head of a newly allocated buffer
     550 *      which has plenty of pointers for subsequent browing.
    505551 *
    506552 *      Use prc32FreeInfo to free the buffer.
     
    513559PQTOPLEVEL32 prc32GetInfo(APIRET *parc)     // out: error, ptr can be NULL
    514560{
    515     #define BUFSIZE (1024 * 1024) // 1 meg
    516 
    517     PCHAR pBuf = NULL; // (PCHAR)malloc(BUFSIZE);
    518 
    519     if (DosAllocMem((PVOID*)&pBuf,
    520                     BUFSIZE,
    521                     PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE)
    522             == NO_ERROR)
    523         if (pBuf)
    524         {
    525             APIRET arc = DosQuerySysState(QS32_SUPPORTED,
    526                                           QS32_SUPPORTED,       // this was missing
    527                                                                 // V0.9.10 (2001-04-08) [umoeller]
    528                                           0, 0,
    529                                           (PCHAR)pBuf,
    530                                           BUFSIZE);
    531             if (parc)
    532                 *parc = arc;
    533 
    534             if (arc == NO_ERROR)
    535                 return ((PQTOPLEVEL32)pBuf);
    536             else
    537                 DosFreeMem(pBuf);
    538         }
    539 
    540     return NULL;
     561    return prc32GetInfo2(QS32_SUPPORTED,
     562                         parc);
    541563}
    542564
     
    594616
    595617    if (pProcThis->ulRecType == 1)
    596         return (pProcThis);
    597     else
    598         return NULL;
     618        return pProcThis;
     619
     620    return NULL;
    599621}
    600622
     
    649671    {
    650672        if (i == usSemID)
    651             return (pSemThis);
     673            return pSemThis;
    652674
    653675        i++;
     
    678700    {
    679701        if (pSemThis->usIndex == usSemID)
    680             return (pSemThis);
     702            return pSemThis;
    681703
    682704        pSemThis = pSemThis->pNext;
     
    704726    {
    705727        if (pShrMem->usHandle == usShrMemID)
    706             return (pShrMem);
     728            return pShrMem;
    707729        pShrMem = pShrMem->pNext;
    708730    }
     
    759781        {
    760782            if (pFile->paFiles[ul].usSFN == usFileID)
    761                 return (pFile);
     783                return pFile;
    762784        }
    763785
     
    768790}
    769791
    770 
     792/*
     793 *@@ prc32KillProcessTree:
     794 *
     795 *@@added XWP V1.0.10 (2014-12-07) [pr]
     796 */
     797
     798void prc32KillProcessTree(ULONG pid)
     799{
     800    APIRET arc;
     801    PQTOPLEVEL32 pInfo = prc32GetInfo2(QS32_PROCESS, &arc);
     802
     803    if (arc == NO_ERROR)
     804    {
     805        prc32KillProcessTree2(pInfo->pProcessData, pid);
     806        DosKillProcess(DKP_PROCESS, pid);
     807        prc32FreeInfo(pInfo);
     808    }
     809}
     810
     811/*
     812 *@@ prc32KillProcessTree2:
     813 *
     814 *@@added XWP V1.0.10 (2014-12-07) [pr]
     815 */
     816
     817void prc32KillProcessTree2(PQPROCESS32 pProcThis, ULONG pid)
     818{
     819    while (pProcThis && pProcThis->ulRecType == 1)
     820    {
     821        PQTHREAD32 t = pProcThis->pThreads;
     822
     823        if (pProcThis->usPPID == pid)
     824        {
     825            prc32KillProcessTree2(pProcThis, pProcThis->usPID);
     826            DosKillProcess(DKP_PROCESS, pProcThis->usPID);
     827        }
     828
     829        // for next process, skip the threads info;
     830        // the next process block comes after the threads
     831        t += pProcThis->usThreadCount;
     832        pProcThis = (PQPROCESS32)t;
     833    }
     834}
     835
  • trunk/include/helpers/procstat.h

    r257 r420  
    1313
    1414/*
    15  *      This file Copyright (C) 1992-99 Ulrich M”ller,
    16  *                                      Kai Uwe Rommel.
     15 *      This file Copyright (C) 1992-2014 Ulrich M”ller,
     16 *                                        Kai Uwe Rommel.
    1717 *      This file is part of the "XWorkplace helpers" source package.
    1818 *      This is free software; you can redistribute it and/or modify
     
    834834                                   USHORT usFileID);
    835835
     836    void prc32KillProcessTree(ULONG pid);
     837
     838    void prc32KillProcessTree2(PQPROCESS32 pProcThis, ULONG pid);
     839
    836840#endif
    837841
  • trunk/src/helpers/procstat.c

    r240 r420  
    3333/*
    3434 *      Copyright (C) 1992-1994 Kai Uwe Rommel.
    35  *      Copyright (C) 1998-2000 Ulrich M”ller.
     35 *      Copyright (C) 1998-2014 Ulrich M”ller.
    3636 *      This file is part of the "XWorkplace helpers" source package.
    3737 *      This is free software; you can redistribute it and/or modify
     
    5252#define INCL_DOSMODULEMGR
    5353#define INCL_DOSERRORS
     54#define INCL_DOSPROCESS
    5455#include <os2.h>
    5556
     
    789790}
    790791
    791 
     792/*
     793 *@@ prc32KillProcessTree:
     794 *
     795 *@@added XWP V1.0.10 (2014-12-07) [pr]
     796 */
     797
     798void prc32KillProcessTree(ULONG pid)
     799{
     800    APIRET arc;
     801    PQTOPLEVEL32 pInfo = prc32GetInfo2(QS32_PROCESS, &arc);
     802
     803    if (arc == NO_ERROR)
     804    {
     805        prc32KillProcessTree2(pInfo->pProcessData, pid);
     806        DosKillProcess(DKP_PROCESS, pid);
     807        prc32FreeInfo(pInfo);
     808    }
     809}
     810
     811/*
     812 *@@ prc32KillProcessTree2:
     813 *
     814 *@@added XWP V1.0.10 (2014-12-07) [pr]
     815 */
     816
     817void prc32KillProcessTree2(PQPROCESS32 pProcThis, ULONG pid)
     818{
     819    while (pProcThis && pProcThis->ulRecType == 1)
     820    {
     821        PQTHREAD32 t = pProcThis->pThreads;
     822
     823        if (pProcThis->usPPID == pid)
     824        {
     825            prc32KillProcessTree2(pProcThis, pProcThis->usPID);
     826            DosKillProcess(DKP_PROCESS, pProcThis->usPID);
     827        }
     828
     829        // for next process, skip the threads info;
     830        // the next process block comes after the threads
     831        t += pProcThis->usThreadCount;
     832        pProcThis = (PQPROCESS32)t;
     833    }
     834}
     835
Note: See TracChangeset for help on using the changeset viewer.