Skip to content

Instantly share code, notes, and snippets.

View adililhan's full-sized avatar

adililhan

View GitHub Profile
#!/bin/bash
trap control_t SIGTERM
function control_t() {
echo "SIGTERM detected"
echo "... Disk cleanup started ..."
sleep 45
echo "... Disk cleanup is complete ..."
exit 0
#!/bin/bash
trap control_t SIGTERM
function control_t() {
echo "SIGTERM detected"
exit 0
}
for i in `seq 1 86400`; do
#!/bin/bash
trap control_t SIGTERM
function control_t() {
echo "SIGTERM detected"
}
for i in `seq 1 86400`; do
sleep 1
#!/bin/bash
trap control_c INT
trap control_z TSTP
function control_c() {
echo "Interrupt detected - CTRL+C"
}
function control_z() {
@adililhan
adililhan / non-reentrant-sigaction-block-signal.c
Created October 17, 2022 20:19
non-reentrant function block signal
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
int sum;
int calculate(int first, int second) {
sum = first + second;
sleep(3); // represent I/O intensive function call
@adililhan
adililhan / non-reentrant-sigaction-global-variable.c
Created October 17, 2022 20:18
non-reentrant function with global variable
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
int sum;
int calculate(int first, int second) {
sum = first + second;
sleep(3); // represent I/O intensive function call
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
int calculate(int first, int second) {
int sum = first + second;
sleep(3); // represent I/O intensive function call
return sum;
}
@adililhan
adililhan / non-reentrant-sigaction-local-variable.c
Created October 17, 2022 20:15
non-reentrant function with local variable
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
int sum;
int calculate(int first, int second) {
sum = first + second;
sleep(3); // represent I/O intensive function call
@adililhan
adililhan / non-reentrant.c
Created October 17, 2022 19:37
non-reentrant function
#include <stdio.h>
#include <unistd.h>
int sum;
int calculate(int first, int second) {
sum = first + second;
sleep(3); // represent I/O intensive function call
return sum;
}
@adililhan
adililhan / reentrant-function-sigaction.rs
Created October 15, 2022 20:11
reentrant function in Rust
use nix::sys::signal::*;
use nix::sys::signal::SigAction;
use std::time::Duration;
use std::thread;
fn calculate(first: i32, second: i32) -> i32 {
let sum = first + second;
thread::sleep(Duration::from_secs(3));
sum
}