Git Product home page Git Product logo

windows-kill's Introduction

windows-kill

windows-kill – Send signal to process by PID in Windows, like POSIX kill

Send signal to process by PID in Windows, like POSIX kill

Windows has no process signaling mechanism like what POSIX provide using the kill command. But windows-kill could send signal to process by PID. :)

Why windows-kill?

Well, I'm a node.js developer. Node has a functionality that could send signals to other process, by their PID. This functionality works great on POSIX OSes but in Windows, no signal is supported (even SIGINT and SIGBREAK, that node stated is supported in Windows), and sending any of those signals to any process in windows, will result in an immediate kill of those process (Even if those process have listener on sent signals). In one of my project signal sending and listening was a serious need, so I've made some research about signal sending in windows, and found an OLD (2003) project named SendSignal. Well that project doesn’t support 64bit systems and also could only send SIGBREAK (Ctrl + Break) signal. More searches lead me to an enhanced version of SendSignal, that add support of 64bit systems, but only support sending SIGINT (Ctrl + C) signal. So I've decided to write a library that support both 32bit & 64bit systems, and also both SIGBREAK and SIGINT signals. The result is the windows-kill-library that has all the functionality I've needed, and is the heart of windows-kill. For information about windows-kill-library navigate to windows-kill-library folder.

Features

  • Support both 32bit (Win32) & 64bit (x64) Windows
  • Support both SIGBREAK (Ctrl + Break) and SIGINT (Ctrl + C) Signals
  • A library that could be used directly (#include), As a static library (.lib) and a dynamic library (.dll)
  • Prebuilt binaries and libraries

How it works & Limitations

To read a detailed info please visit windows-kill-library Readme. But it's good to know that windows-kill will create a ctrl event in the process that is calling it. If the caller process has no child process or not a child process of another process, nothing will happen. But if has child process or is child process, sending signal will trigger the ctrl routine of all processes in the process group, and as a result, those process will be terminated.

Installation

Chocolatey - 32bit (Win32) and 64bit (x64)

Install

> choco install windows-kill

Update

> choco upgrade windows-kill

Prebuilt Binaries

You can also download the prebuilt binaries of windows-kill. You could find them in repo's Releases page. Both the 32bit (Win32) and 64bit (x64) versions are available.

Compile & Build from Source code

If you want to compile from the source code, you must install Visual Studio plus C++ development tools first. I'm developing this project in Visual Studio 2015 update 3. So it's recommended to use the same Visual Studio version. But maybe other versions are ok to use. Also I didn't compile the project using other C++ compilers. So any contribution to add other compilers support is welcomed!

After the Visual Studio installation, clone the GitHub project or download the latest master branch source code and extract the downloaded zip. Go to the project folder and open the windows-kill.sln in Visual Studio. From the build menu, click on batch build. There you could see different build configurations. For more information about build configuration see Build Configurations.

Usage Examples

Using the windows-kill is easy & straightforward. It's just like POSIX kill. Just navigate to the folder that contains windows-kill.exe and open a cmd from that folder. Or add that folder in Environment Variables so you could use the command from any cmd. If signal sending was successful or any error occurred during the sending, appropriate message will be print in cmd.

Sending signal to PID

> windows-kill -SIGNALTYPE PID

Sending SIGBREAK (Ctrl + Break) to sample 1234 PID

> windows-kill -SIGBREAK 1234
> windows-kill -1 1234

Sending SIGINT (Ctrl + C) to sample 1234 PID

> windows-kill -SIGINT 1234
> windows-kill -2 1234

List supported signal types

> windows-kill -l

Usage help

> windows-kill -h

Build Configurations

windows-kill Visual Studio solution contains different build configuration. There are two main Debug and Release configuration category. Each of these categories have two separate configurations for building the windows-kill-library as a dynamic link library (.dll) or static link library (.lib). Also all the build configurations in Visual Studio has 32bit (Win32) & 64bit (x64) versions. In Summary there are 4 build configurations:

  • Debug Dll: Build windows-kill-library as a .dll with debug enabled.
  • Debug Lib: Build windows-kill-library as a .lib with debug enabled.
  • Release Dll: Build windows-kill-library as a .dll without debug.
  • Release Lib: Build windows-kill-library as a .lib without debug.

Resources

The windows-kill & windows-kill-library are based on:

Contributing

We love contributions from everyone. Please read Contributing guide.

License

MIT

windows-kill's People

Contributors

aliirdn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-kill's Issues

No support for CTRL_CLOSE_EVENT (closing console processes)

I could make use of windows-kill to test GNU Bash's behavior when a terminal is closed, if only the relevant signal (CTRL_CLOSE_EVENT) was supported. That signal is described in the HandlerRoutine function's documentation:

A signal that the system sends to all processes attached to a console when the user closes the console (either by clicking Close on the console window's window menu, or by clicking the End Task button command from Task Manager).

"Terminate the batch process (yes/no)?" prompt if run from batch

As the title suggests, if I use the software within a batch, this will ask me if I want to terminate it (choosing "no" continues the rest of the batch).

My .bat output
B:\App>KomgaUpdater.bat

B:\App>setlocal

B:\App>set "yourDir=B:\SERVER\Komga\"

B:\App>set "yourExt=*.jar"

B:\App>pushd B:\SERVER\Komga\

B:\SERVER\Komga>for %a in (*.*.jar) do set Komga=%a

B:\SERVER\Komga>set Komga=komga-0.157.1.jar

B:\SERVER\Komga>popd

B:\App>for /F "TOKENS=1" %a in ('wmic PROCESS where "name like '%java.exe%' AND CommandLine like '%java.exe% -jar -Xmx3g komga-0.157.1.jar%'" get Processid | findstr [0-9]') do set MyPID=%a

B:\App>set MyPID=11708

B:\App>echo  11708
 11708

B:\App>B:\App\Windows-Kill\windows-kill.exe -2 11708
Windows Kill 1.1.4 | Windows Kill Library 3.1.3
Signal sent successfuly. type: 0 | pid: 11708
Terminare il processo batch (S/N)? n

B:\App>TIMEOUT /T 10

In attesa da  0 secondi. Premere un tasto per continuare...

B:\App>cd "B:\SERVER\Komga\"

B:\SERVER\Komga>del "komga-0.157.1.jar"

B:\SERVER\Komga>lastversion download https://github.com/gotson/komga --assets
Downloaded komga-0.157.2.jar: : 135336.0KB [00:27, 4979.18KB/s]
Downloaded komga-0.157.2.jar.sha256: : 8.0KB [00:00, 2001.58KB/s]

B:\SERVER\Komga>start "komga" "C:\Users\Administrator\Desktop\Komga.lnk"

B:\SERVER\Komga>endlocal

B:\App>pause
Premere un tasto per continuare . . .
B:\App>

Having to enter "n" by hand to get the script to continue is not the best...

Having a switch that prevents the program from prompting (if possible) would be handy.
Type: Windows-kill.exe --no-prompt -2 1234

Thanks in advance

More sigs to come ?

Will other signals will be supported in next versions like SIGSEV & all others you can have with kill -l with POSIX ?

Does not seem to work w/o reporting any error

I have a Console application which is correctly terminated via SendSignal original application, however, it does not work with "windows-kill" which I've installed via Chocolatey (version of package is 1.1.4 as of now) and it does not produce any error output.

image

> windows-kill -1 42128
Windows Kill 1.1.4 | Windows Kill Library 3.1.3
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.18363 N/A Build 18363
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free

MinGW library support

It would be great if windows-kill-library had a library that could be linked using MinGW, for development without Visual Studio.

MinGW does support linking .lib files in recent versions, but it doesn't seem to know what to do with the windows-kill-library release libraries. I've tried converting the .lib file to .a using lib2a, but no dice.

Add warm-up method to windows-kill-library

Add a function to window-kill-library Sender class, that will get the control-routine address. Currently control-routine address is retrieved when the send is called and during the sending procedure.

windows-kill.exe occasionally fails for Windows after May 2020 Update

After updating Windows to version 10.0.19041.388 (May 2020 Update), then windows-kill.exe started to occasionally fail like this:

[BOOTCAMP] [sigmund-MAC2-dev] 00:25 0.634 155649M d:\dev>base-00\exe\windows-kill.exe -SIGINT 496
Windows Kill 1.1.4 | Windows Kill Library 3.1.3
RuntimeError: windows-kill-library: ctrl-routine:findAddress:checkAddressIsNotNull

^C

This is for the pre-built windows-kill.exe for 1.1.4.

Crashes when trying to send signal to a CMD started process

I'm starting my main application with the following command:
C:\WINDOWS\system32\cmd.exe /c start /min /"Main-Application\" /high /b MyProcess.exe

When I invoke windows-kill to send a CTRL + C to a process spawned by MyProcess it crashes windows-kill at the following location:

Exception thrown at 0x00007FFE8B8853F5 (KernelBase.dll) in windows-kill.exe: 0x40010005: Control-C.

image

This is especially nasty since it caused a hang of the application because it waits for windows-kill's completion.

Can this be fixed? If not, maybe you can suggest me an alternative way of sending a CTRL + C button press to a process on Windows. I'm using Java 8's ProcessBuilder though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.