1660519800
Send CTRL-C to a Windows console application
Long running stateful processes like servers often hold a lot of system resources that they need to operate. These are things like communication ports, file descriptors, database connections, etc... At some point, when it is time for that process to shut it needs to release all those resources back to the operating system and exit. This process of freeing up all the things that were being used is called "graceful shutdown" and is really important to get right in systems that start and stop processes repeatedly. On Unix systems, the method for achieving a graceful shutdown of a process is to send it a signal (usually either SIGINT
or SIGTERM
).
The process can then register a handler for this signal which releases any resources that it is holding and exits.
The alternative to a graceful shutdown is a "forced termination". This is what happens when a process is unable to respond to a interrupt or termination signal. In this case, the process is ended immediately without the opprotunity to release any of the resources it holds.
On Unix systems, when you invoke process.kill()
on a ChildProcess
object, it sends the SIGTERM
signal. That way, if the process has a SIGTERM
handler it has an opportunity to perform a graceful shutdown.
Windows on the other hand, does not have a method to send signals to a process, so when you invoke the same process.kill()
function on that platform, what you end up with is a forceful termination without any cleanup. However, Windows does have a method for applications to shutdown gracefully, namely hitting CTRL-C
on the console to which the process is attached. And that's what this is all about. In fact, whenever you hit CTRL-C
on a windows console that is running a node
application, node
will translate that CTRL-C
into a SIGINT
and dispatch any SIGINT
handlers that it has registered. Since most well-behaved long-running Nodejs processes respond to SIGINT
, this allows them to shutdown too.
This module exports a single ctrlc
function which accepts a process id, and sends a CTRL-C
event to that console.
Note: This is a no-op on non-windows platforms
import { ctrlc } from 'ctrlc-windows';
export function gracefulShutdown(process) {
if (process.platform === 'win32') {
ctrlc(process.pid);
} else {
process.kill();
}
}
Author: Thefrontside
Source Code: https://github.com/thefrontside/ctrlc-windows
1660519800
Send CTRL-C to a Windows console application
Long running stateful processes like servers often hold a lot of system resources that they need to operate. These are things like communication ports, file descriptors, database connections, etc... At some point, when it is time for that process to shut it needs to release all those resources back to the operating system and exit. This process of freeing up all the things that were being used is called "graceful shutdown" and is really important to get right in systems that start and stop processes repeatedly. On Unix systems, the method for achieving a graceful shutdown of a process is to send it a signal (usually either SIGINT
or SIGTERM
).
The process can then register a handler for this signal which releases any resources that it is holding and exits.
The alternative to a graceful shutdown is a "forced termination". This is what happens when a process is unable to respond to a interrupt or termination signal. In this case, the process is ended immediately without the opprotunity to release any of the resources it holds.
On Unix systems, when you invoke process.kill()
on a ChildProcess
object, it sends the SIGTERM
signal. That way, if the process has a SIGTERM
handler it has an opportunity to perform a graceful shutdown.
Windows on the other hand, does not have a method to send signals to a process, so when you invoke the same process.kill()
function on that platform, what you end up with is a forceful termination without any cleanup. However, Windows does have a method for applications to shutdown gracefully, namely hitting CTRL-C
on the console to which the process is attached. And that's what this is all about. In fact, whenever you hit CTRL-C
on a windows console that is running a node
application, node
will translate that CTRL-C
into a SIGINT
and dispatch any SIGINT
handlers that it has registered. Since most well-behaved long-running Nodejs processes respond to SIGINT
, this allows them to shutdown too.
This module exports a single ctrlc
function which accepts a process id, and sends a CTRL-C
event to that console.
Note: This is a no-op on non-windows platforms
import { ctrlc } from 'ctrlc-windows';
export function gracefulShutdown(process) {
if (process.platform === 'win32') {
ctrlc(process.pid);
} else {
process.kill();
}
}
Author: Thefrontside
Source Code: https://github.com/thefrontside/ctrlc-windows
1620171720
First off, let’s create a .NET Core console application project in Visual Studio. Assuming Visual Studio 2019 is installed in your system, follow the steps outlined below to create a new .NET Core console application project in Visual Studio.
This will create a new .NET Core console application project in Visual Studio 2019. We’ll use this project to work with the Windows event log in the subsequent sections of this article.
#windows event #c# #windows event log
1624240146
C and C++ are the most powerful programming language in the world. Most of the super fast and complex libraries and algorithms are written in C or C++. Most powerful Kernel programs are also written in C. So, there is no way to skip it.
In programming competitions, most programmers prefer to write code in C or C++. Tourist is considered the worlds top programming contestant of all ages who write code in C++.
During programming competitions, programmers prefer to use a lightweight editor to focus on coding and algorithm designing. Vim, Sublime Text, and Notepad++ are the most common editors for us. Apart from the competition, many software developers and professionals love to use Sublime Text just because of its flexibility.
I have discussed the steps we need to complete in this blog post before running a C/C++ code in Sublime Text. We will take the inputs from an input file and print outputs to an output file without using freopen
file related functions in C/C++.
#cpp #c #c-programming #sublimetext #c++ #c/c++
1597937354
If you are familiar with C/C++then you must have come across some unusual things and if you haven’t, then you are about to. The below codes are checked twice before adding, so feel free to share this article with your friends. The following displays some of the issues:
The below code generates no error since a print function can take any number of inputs but creates a mismatch with the variables. The print function is used to display characters, strings, integers, float, octal, and hexadecimal values onto the output screen. The format specifier is used to display the value of a variable.
A signed integer is a 32-bit datum that encodes an integer in the range [-2147483648 to 2147483647]. An unsigned integer is a 32-bit datum that encodes a non-negative integer in the range [0 to 4294967295]. The signed integer is represented in twos-complement notation. In the below code the signed integer will be converted to the maximum unsigned integer then compared with the unsigned integer.
#problems-with-c #dicey-issues-in-c #c-programming #c++ #c #cplusplus
1596757307
#oop in c# #object oriented programming in c# #object oriented concept in c# #learn oop concept #advance c# #delegates in c#