Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2007.06.24;
Скачать: [xml.tar.bz2];

Вниз

Приостановка процесса   Найти похожие ветки 

 
Cj ©   (2007-01-11 16:32) [0]

Есть ли процедуры приостановки процесса, и его возобновления?


 
Джо ©   (2007-01-11 16:35) [1]

Есть. Но, собственно, не процессов, а потоков.
См. SuspendThread, ResumeThread.


 
Anatoly Podgoretsky ©   (2007-01-11 16:37) [2]

> Джо  (11.01.2007 16:35:01)  [1]

Но вопрос то про процессы, а процесс самодостаточен, по сути это запуск другой программы.


 
Cj ©   (2007-01-11 16:38) [3]

В смысле я это и имел в виду.Спасибо


 
Джо ©   (2007-01-11 16:47) [4]

> [2] Anatoly Podgoretsky ©   (11.01.07 16:37)

Ну, если приостановить все потоки процесса, то и процесс будет «приостановлен» :)


 
Игорь Шевченко ©   (2007-01-11 16:58) [5]

Есть в Windows 2003 и выше (NtSuspendProcess, NtResumeProcess)


 
Cj ©   (2007-01-11 17:12) [6]

а в каком Unit они? Где его найти?


 
Игорь Шевченко ©   (2007-01-11 17:24) [7]


> а в каком Unit они?


в Jedi поищи


 
Cj ©   (2007-01-11 17:28) [8]

Я наверно камер.Где это и что это?


 
clickmaker ©   (2007-01-11 17:33) [9]


> [8] Cj ©   (11.01.07 17:28)
> Я наверно камер

это кто?!


 
Джо ©   (2007-01-11 17:33) [10]

В Jedi вроде нету.


 
Cj ©   (2007-01-11 17:34) [11]

МНЕ это очень нужно


 
Джо ©   (2007-01-11 17:35) [12]

> [11] Cj ©   (11.01.07 17:34)
> МНЕ это очень нужно

И?


 
Cj ©   (2007-01-11 17:41) [13]

Пожалуйста помогите


 
Anatoly Podgoretsky ©   (2007-01-11 17:43) [14]

> Джо  (11.01.2007 17:33:10)  [10]

Конечно в Jedi камеров нет


 
Cj ©   (2007-01-11 17:45) [15]

или как от ID процесса получить Thread


 
Джо ©   (2007-01-11 17:50) [16]

> [15] Cj ©   (11.01.07 17:45)
> или как от ID процесса получить Thread


Traversing the Thread List
The following example function lists running threads for a specified process. First, the ListProcessThreads function takes a snapshot of the currently executing threads in the system using CreateToolhelp32Snapshot, and then it walks through the list recorded in the snapshot using Thread32First and Thread32Next. The parameter for ListProcessThreads is the process identifier of the process whose threads are to be listed.

#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>

//  Forward declarations:
BOOL ListProcessThreads( DWORD dwOwnerPID );
void printError( TCHAR* msg );

void main( )
{
 ListProcessThreads(GetCurrentProcessId() );
}

BOOL ListProcessThreads( DWORD dwOwnerPID )
{
 HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
 THREADENTRY32 te32;

 // Take a snapshot of all running threads  
 hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
 if( hThreadSnap == INVALID_HANDLE_VALUE )
   return( FALSE );

 // Fill in the size of the structure before using it.
 te32.dwSize = sizeof(THREADENTRY32 );

 // Retrieve information about the first thread,
 // and exit if unsuccessful
 if( !Thread32First( hThreadSnap, &te32 ) )
 {
   printError( "Thread32First" );  // Show cause of failure
   CloseHandle( hThreadSnap );     // Must clean up the snapshot object!
   return( FALSE );
 }

 // Now walk the thread list of the system,
 // and display information about each thread
 // associated with the specified process
 do
 {
   if( te32.th32OwnerProcessID == dwOwnerPID )
   {
     printf( "\n\n     THREAD ID      = 0x%08X", te32.th32ThreadID );
     printf( "\n     base priority  = %d", te32.tpBasePri );
     printf( "\n     delta priority = %d", te32.tpDeltaPri );
   }
 } while( Thread32Next(hThreadSnap, &te32 ) );

//  Don"t forget to clean up the snapshot object.
 CloseHandle( hThreadSnap );
 return( TRUE );
}

void printError( TCHAR* msg )
{
 DWORD eNum;
 TCHAR sysMsg[256];
 TCHAR* p;

 eNum = GetLastError( );
 FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL, eNum,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
        sysMsg, 256, NULL );

 // Trim the end of the line and terminate it with a null
 p = sysMsg;
 while( ( *p > 31 ) || ( *p == 9 ) )
   ++p;
 do { *p-- = 0; } while( ( p >= sysMsg ) &&
                         ( ( *p == "." ) || ( *p < 33 ) ) );

 // Display the message
 printf( "\n  WARNING: %s failed with error %d (%s)", msg, eNum, sysMsg );
}


(c) MSDN.


 
GrayFace ©   (2007-01-12 02:52) [17]

Рихтер тебе в помощь:

Suspending and Resuming a Process

The concept of suspending or resuming a process doesn"t exist for Windows since processes are never scheduled CPU time. However, I have been asked numerous times how to suspend all of the threads in a process. Windows does allow one process to suspend all the threads in another process, but the process doing the suspending must be a debugger. Specifically, the process must call functions such as WaitForDebugEvent and ContinueDebugEvent.

Windows doesn"t offer any other way to suspend all threads in a process because of race conditions. For example, while the threads are suspended, a new thread might be created. Somehow the system must suspend any new threads during this window of time. Microsoft has integrated this functionality into the debugging mechanism of the system.

While you cannot create an absolutely perfect SuspendProcess function, you can create an implementation of this function that works well in many situations. Here is my implementation of a SuspendProcess function:

VOID SuspendProcess(DWORD dwProcessID, BOOL fSuspend) {

  // Get the list of threads in the system.
  HANDLE hSnapshot = CreateToolhelp32Snapshot(
     TH32CS_SNAPTHREAD, dwProcessID);

  if (hSnapshot != INVALID_HANDLE_VALUE) {

     // Walk the list of threads.
     THREADENTRY32 te = { sizeof(te) };
     BOOL fOk = Thread32First(hSnapshot, &te);
     for (; fOk; fOk = Thread32Next(hSnapshot, &te)) {

        // Is this thread in the desired process?
        if (te.th32OwnerProcessID == dwProcessID) {

           // Attempt to convert the thread ID into a handle.
           HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME,
              FALSE, te.th32ThreadID);

           if (hThread != NULL) {

              // Suspend or resume the thread.
              if (fSuspend)
                 SuspendThread(hThread);
              else
                 ResumeThread(hThread);
           }
           CloseHandle(hThread);
        }
     }
     CloseHandle(hSnapshot);
  }
}


Работает начиная с Win2000. Русский Рихтер находится здесь: http://rouse.drkb.ru/books/rihter.zip



Страницы: 1 вся ветка

Форум: "WinAPI";
Текущий архив: 2007.06.24;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.5 MB
Время: 0.039 c
2-1180626487
FIL-23
2007-05-31 19:48
2007.06.24
округление


2-1180939599
allucard
2007-06-04 10:46
2007.06.24
В чём отличие приведения типов?


15-1180280239
No_Dead
2007-05-27 19:37
2007.06.24
То же литература понадобилась, нужен совет


11-1162495313
UnknownUndead
2006-11-02 22:21
2007.06.24
Приложение - Сервис


2-1180690269
Dominic
2007-06-01 13:31
2007.06.24
Подскажите, помогите!





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский