Python Forum
how to terminate all the processes in C
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to terminate all the processes in C
#1
win 7 I have used C to write a project, and compile it to dll to be used in a big program writing with python.After finished using the DLL, although I have used the closing com port function in the dll, the com port was still be used.
In the end of the dll, all the thread was terminated but I suspect a memory overflow problem so I want to forcely kill all the process at the end of the dll. I tried pid_t pid = getpid() but it could not be used and I think it may only be used in linux, so how to terminate all the process so the com port could be released after using the dll?

#include <windows.h>

#include <tchar.h>
#include <sys/types.h>
#include <stdio.h>
#include <conio.h>
#include <signal.h>
#include "getopt.h"
#include "download_main.h"
......

#ifdef CREATE_SEND_THREAD
TerminateSendThread();
#endif

TerminateMonitorThread();


release_async_io();

if (hCom != INVALID_HANDLE_VALUE) {
unconfig_serial_port();

fSuccess = CloseHandle(hCom);
if (!fSuccess) {
TRACE("CloseHandle failed with error %d", GetLastError());
} else {
hCom = INVALID_HANDLE_VALUE;
TRACE("Serial port %s successfully closed", commPort);
}
}
free_programmer_data();
//free_flash_data();
deinit_download_var();
deinit_pyext_sync_event();

if(!!g_dldtool_exit_code)
app_ev_notify(ev_wm_exit_invalid, 0);
else
app_ev_notify(ev_wm_exit_valid, 0);
TRACE("download exit code:%d\n",g_dldtool_exit_code);


pid_t pid = getpid();
system("tskill pid");
return g_dldtool_exit_code;
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  processes shall be parallel flash77 4 1,066 Sep-20-2022, 11:46 AM
Last Post: DeaD_EyE
  Sharing imported modules with Sub Processes? Stubblemonster 2 1,462 May-02-2022, 06:42 AM
Last Post: Stubblemonster
  Killing processes via python Lavina 2 2,560 Aug-04-2021, 06:20 AM
Last Post: warnerarc
  The game should now run and terminate once the board is full, but still can’t identif rango 0 1,431 Jul-22-2021, 03:24 AM
Last Post: rango
  How to share a numpy array between 2 processes on Windows? qstdy 0 2,137 Jan-29-2021, 04:24 AM
Last Post: qstdy
  sharing variables between two processes Kiyoshi767 1 1,848 Nov-07-2020, 04:00 AM
Last Post: ndc85430
  2 or more processes on the write end of the same pipe Skaperen 4 3,792 Sep-27-2020, 06:41 PM
Last Post: Skaperen
  Errors using --processes parameter sonhospa 3 2,349 Jul-01-2020, 02:24 PM
Last Post: sonhospa
  Is there a way to not terminate a running thread in python Contra_Boy 3 1,933 May-05-2020, 09:38 PM
Last Post: SheeppOSU
  Terminate a process when hotkey is pressed 66Gramms 0 2,210 Dec-24-2019, 06:41 PM
Last Post: 66Gramms

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020