Skip to content

Instantly share code, notes, and snippets.

View kgbook's full-sized avatar
:octocat:
Focusing

kgbook kgbook

:octocat:
Focusing
View GitHub Profile
@kgbook
kgbook / atexit_example.cpp
Last active November 12, 2018 12:07
[atexit example]register a function to be called at normal process termination #atexit #interprocess
#include <iostream>
#include <cstdlib>
#include <unistd.h>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <sys/wait.h>
void parent_process_callback() {
std::cout <<__func__ <<", pid: " <<getpid() <<std::endl;
@kgbook
kgbook / SharedSemaphore.h
Last active November 12, 2018 12:12
[interprocess semaphore example]interprocess semaphore example #interprocess #semaphore
#ifndef SHARED_SEMAPHORE_H
#define SHARED_SEMAPHORE_H
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <sys/types.h>
#include <semaphore.h>
#include <fcntl.h>
@kgbook
kgbook / boost_thread_interrupt.cpp
Last active November 12, 2018 12:07
[boost thread interrupt]example of boost::thread interruption #interrupt #multithreading #boost
#include <iostream>
#include <boost/chrono/chrono.hpp>
#include <boost/thread/thread.hpp>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
static pid_t child_pid = 0;
void child_process_thread_func() {
@kgbook
kgbook / boost_variant_example.cpp
Last active November 15, 2018 18:34
[boost variant example]boost::variant example #boost #variant
#include <boost/variant.hpp>
#include <string>
#include <iostream>
using data_t = boost::variant<
bool,
int8_t,
uint8_t,
int16_t,
uint16_t,
@kgbook
kgbook / inheritance_example.cpp
Last active November 28, 2018 04:25
[inheritance example]inheritance #inheritance #C++
#include <iostream>
//using namespace std::cout;
class Subject
{
public:
Subject() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
@kgbook
kgbook / boost_thread_interruption.cpp
Created November 30, 2018 07:33
[boost thread interruption example] boost thread interruption example #boost::thread::interrupt
#include <iostream>
#include <boost/thread.hpp>
using std::cout;
using std::endl;
void sayHello() {
int32_t cnt = 0;
while (!boost::this_thread::interruption_requested()) {
@kgbook
kgbook / interrupt_sleep.cpp
Last active April 19, 2019 09:09
#thread_sleep #interrupt_sleep
//
// Created by kang on 2019-04-19.
//
#include <chrono>
#include <iostream>
#include "interrupt_sleep.h"
using namespace std::chrono;
@kgbook
kgbook / parseIP.cpp
Created May 20, 2019 13:01
#ip #parse_ip
#include <string>
#include <sstream>
#include <iostream>
int getIP(std::string ip_str) {
if (ip_str.empty()) {
return 0;
}
std::stringstream ss(ip_str);
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <string>
std::string exec_cmd(std::string cmd) {
if (cmd.empty()) {
return "";
}