All Projects → alanfranz → Killmesoftly

alanfranz / Killmesoftly

Licence: other
Kill processes The Right Way.

Labels

Projects that are alternatives of or similar to Killmesoftly

Chromium Headless Remote
🐳 Dockerized Chromium in headless remote debugging mode
Stars: ✭ 122 (-4.69%)
Mutual labels:  makefile
Onl
Please visit the Open Compute Project repository
Stars: ✭ 125 (-2.34%)
Mutual labels:  makefile
Mls Protocol
MLS protocol
Stars: ✭ 127 (-0.78%)
Mutual labels:  makefile
Mmake
Mmake is a small program which wraps make to provide additional functionality, such as user-friendly help output, remote includes, and eventually more. It otherwise acts as a pass-through to standard make.
Stars: ✭ 1,593 (+1144.53%)
Mutual labels:  makefile
Executors
A proposal for a executor programming model for ISO C++
Stars: ✭ 124 (-3.12%)
Mutual labels:  makefile
Base
Minimal BusyBox Docker container
Stars: ✭ 126 (-1.56%)
Mutual labels:  makefile
Awesome Dtrace
A curated list of awesome DTrace books, articles, videos, tools and resources.
Stars: ✭ 121 (-5.47%)
Mutual labels:  makefile
Embedded Ide
IDE for C embedded development centered on bare-metal ARM systems
Stars: ✭ 127 (-0.78%)
Mutual labels:  makefile
Easymake
A handy makefile for simple C/C++ applications
Stars: ✭ 125 (-2.34%)
Mutual labels:  makefile
Biscuitos
Common scripts to build BiscuitOS
Stars: ✭ 128 (+0%)
Mutual labels:  makefile
Pkgsrc
[Please switch to NetBSD/pkgsrc] Automatically updated conversion of the "pkgsrc" module from anoncvs.netbsd.org
Stars: ✭ 123 (-3.91%)
Mutual labels:  makefile
Apiproject
[https://www.sofineday.com], golang项目开发脚手架,集成最佳实践(gin+gorm+go-redis+mongo+cors+jwt+json日志库zap(支持日志收集到kafka或mongo)+消息队列kafka+微信支付宝支付gopay+api加密+api反向代理+go modules依赖管理+headless爬虫chromedp+makefile+二进制压缩+livereload热加载)
Stars: ✭ 124 (-3.12%)
Mutual labels:  makefile
Webnn
🧠 Web Neural Network API
Stars: ✭ 126 (-1.56%)
Mutual labels:  makefile
I2c Master Lib
This is an I2C master library I wrote for use with AVR 8 bit microcontrollers
Stars: ✭ 122 (-4.69%)
Mutual labels:  makefile
Openelec.tv
OpenELEC - The living room PC for everyone
Stars: ✭ 1,595 (+1146.09%)
Mutual labels:  makefile
Genericmakefile
A generic makefile for use with small/medium C and C++ projects.
Stars: ✭ 1,587 (+1139.84%)
Mutual labels:  makefile
3dshomebrew
3DS homebrew tutorial
Stars: ✭ 126 (-1.56%)
Mutual labels:  makefile
Buildroot
Buildroot Environment for multiple TV WebKit ports using EGL and GLESv2, supporting WebGL, Canvas, HTML5 Video as a texture and more. One of the target devices supported is the Raspberry PI 2.
Stars: ✭ 127 (-0.78%)
Mutual labels:  makefile
Csvlint
library and command line tool that validates a CSV file
Stars: ✭ 127 (-0.78%)
Mutual labels:  makefile
Hackable Consumer Hardware
List of hackable consumer hardware products
Stars: ✭ 127 (-0.78%)
Mutual labels:  makefile

Kill Me Softly

Kill processes The Right Way.

Purpose

An incredible number of times, I had to perform a simple task: killing a process, and making sure the process was dead before proceeding.

Sometimes the process doesn't die by SIGTERM, and you need to send a SIGKILL.

In some (rare) situations, the process doesn't die by SIGKILL either.

Sometimes the process just takes some time to die.

By the way, what I usually want is something like hey, kill this process and don't go on until it's dead.

It's stupid, but it's everything killmesoftly does; it tries to send a SIGTERM to a process, if it doesn't die within 15 seconds it sends a SIGKILL, if it still doesn't die it reports it.

AFAIK there's no other tool to do that, even though such logic is implemented in a lot of software and service scripts.

Install

Standalone executables

This is the recommended way to go if you just want to use this tool, at least until I don't submit it to Homebrew and Linuxbrew.

Go anywhere in your executable path and download the latest standalone version of kmsp and kmsn.

wget https://www.franzoni.eu/releases/killmesoftly/master/kmsp https://www.franzoni.eu/releases/killmesoftly/master/kmsn
chmod +x ./kmsp ./kmsn

From Github source

Build and install

Just clone this repository, or download a packed zip, and use

make install

by default, this will install standalone executables in /usr/local/bin. If you want to change your install destination:

make PREFIX=/tmp/asd install

will install in /tmp/asd/bin or

make BINDIR=/tmp/mydir install

will install in /tmp/mydir.

Make-less installation

Otherwise, for a make-less install, you could just copy kmsp and kmsn in your path, set them executable, make sure kms_functions is in the same directory, and you're ready to go.

Developer-wise installation

If you want to develop changes to killmesoftly, just symlink kmsp, kmsn and kms_functions to a directory in your path (e.g. ~/bin)

Usage

You can feed the two scripts with process names (or matching expression, that will be sent to pgrep) or PIDs, respectively.

The approach is blocking by design: the script won't exit until the process is actually dead, and latter PIDs or names won't be killed until previous ones are dead.

If there's an error on one parameter (e.g. you've specified a name which matches more than one process, or a non-existent PID) the scripts will go on with the other parameters; on the contrary, if there's an hard error (e.g. a process that doesn't exit on a SIGKILL) the whole kill chain will be stopped and an error will be returned.

The default timeout is 15 seconds. It's currently hardcoded.

kmsn

Kill processes softly by name matching pattern.
Usage:
kmsn first_pgrep_pattern [second_pgrep_pattern] <...>

kmsp

Kill processes softly by pid number
Usage:
kmsp first_pid_to_kill [second_pid_to_kill] <...>

Requirements

Those should be available on almost any Linux system, even on minimal installs, and are installed by default in OSX.

  • Linux or OSX
  • Bash
  • Kill and pgrep executables (e.g. procps package on Ubuntu/Debian)

License

This is Apache-2.0 licensed, which is the most permissive license I could think of. Feel free to include and modify this code however you like.

TODOs

  • *BSD support
  • a --all switch for kmsp that allows killing all processes that match a certain parameter
  • consider whether we should return different exit codes in the event some parameters are wrong; currently we return a nonzero exit code only on zero-parameters passed or hard failures.
  • allow specifying a different signal rather than SIGTERM for soft kill, and/or additional signals to be sent before/after SIGTERM.
  • configurable timeouts
  • consider transforming such scripts in a set of functions that can be sourced, rather than used as executables
  • add options for killing process groups and/or check whether children have actually exited
  • add options for matching on full name, not just on process name
  • remove dependency on bash and let sh suffice.
  • add tool in Linuxbrew and Homebrew repositories for easy install.
  • make the testsuite runnable on OSX (currently prevented by extended sed regexp)

Thanks

The following people helped developing this software in some way or another, without a specific order.

  • Jean-Philippe Daigle
  • Laurent Cozic
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].