#include #include #include class A { public: A() : m_val(10) { printf("process %d, this = %p, m_val = %d, A constructor called!!!\n", getpid(), this, m_val); } ~A() { printf("process %d, this = %p, m_val = %d, A destructor called!!!\n", getpid(), this, m_val); } void Inc() { m_val++; printf("process %d, this = %p, m_val = %d, INC called!!!\n", getpid(), this, m_val); } private: int m_val; }; extern "C" { A gA; void IncA() { gA.Inc(); } } /*int main(int argc, char* argv[]) { int pid = getpid(); std::string fname = "/proc/"; fname += std::to_string(pid) + "/cmdline"; std::ifstream ifile(fname); std::string name; std::getline(ifile, name); int beginIdx = name.rfind('/'); name = name.substr(beginIdx + 1); printf("%s\n", name.c_str()); std::string newName = name + std::string("_profile.csv"); printf("%s\n", newName.c_str()); std::string name1 = "a.out"; std::string newName1 = name1 + std::string("_profile.csv"); printf("%s\n", newName1.c_str()); //name.pop_back(); printf("parent process id is %d!!!\n", getpid()); auto pid = fork(); if (pid == 0) { gA.Inc(); } else if (pid > 0) { printf("child process id is %d!!!\n", pid); gA.Inc(); gA.Inc(); sleep(2); } return 0; }*/