g++ test.cpp -I/usr/local/rudiments/include -L/usr/local/rudiments/lib/ -lrudiments
test.cpp
刚一运行a.out奶奶的报错:难怪sqlrelay老是很多麻烦,呵呵
解决步骤:
1、vi /etc/ld.so.conf.d/fuse.conf (新增一个文件)
写入:/usr/local/rudiments/lib( librudiments-0.32.so.1所在位置)
2、ldconfig(重新载入系统)
[root@localhost sqlrelay]# ./a.out
17526: child looping...
17525: parent looping...
[root@localhost sqlrelay]# 17526: child looping...
大功告成!
这样指定也可以:
更多相关编程,参考如下网站:
来源:
http://rudiments.sourceforge.net/rudiments/programming/baseclasses.html#daemon
test.cpp
// Copyright (c) 2001 David Muse
// See the file COPYING for more information
#include <rudiments/daemonprocess.h>
#include <rudiments/permissions.h>
#include <rudiments/process.h>
#include <rudiments/file.h>
#include <rudiments/snooze.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#ifdef RUDIMENTS_NAMESPACE
using namespace rudiments;
#endif
daemonprocess *dmn;
// define a function to shut down the process cleanly
RETSIGTYPE shutDown() {
printf("%d: shutting down\n",process::getProcessId());
// clean up
delete dmn;
file::remove("/tmp/dmn.pidfile");
exit(0);
}
int main(int argc, const char **argv) {
dmn=new daemonprocess();
// set up signal handlers for clean shutdown
dmn->handleShutDown((RETSIGTYPE *)shutDown);
dmn->handleCrash((RETSIGTYPE *)shutDown);
// change the user/group that the daemon is running as
dmn->runAsUser("nobody");
dmn->runAsGroup("nobody");
// make sure that only one instance is running
int pid=dmn->checkForPidFile("/tmp/dmn.pidfile");
if (pid>-1) {
printf("Sorry, an instance of this daemon is already running with process id: %d\n",pid);
delete dmn;
exit(0);
}
// detach from the controlling terminal
dmn->detach();
// create a pid file which is used to make sure that only one instance
// is running and can also be used to kill the process
dmn->createPidFile("/tmp/dmn.pidfile",permissions::ownerReadWrite());
if (!fork()) {
for (;;) {
printf("%d: child looping...\n",
process::getProcessId());
snooze::macrosnooze(1);
}
}
// loop, printing "looping..." once per second
for (;;) {
printf("%d: parent looping...\n",
process::getProcessId());
snooze::macrosnooze(1);
}
}
// See the file COPYING for more information
#include <rudiments/daemonprocess.h>
#include <rudiments/permissions.h>
#include <rudiments/process.h>
#include <rudiments/file.h>
#include <rudiments/snooze.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#ifdef RUDIMENTS_NAMESPACE
using namespace rudiments;
#endif
daemonprocess *dmn;
// define a function to shut down the process cleanly
RETSIGTYPE shutDown() {
printf("%d: shutting down\n",process::getProcessId());
// clean up
delete dmn;
file::remove("/tmp/dmn.pidfile");
exit(0);
}
int main(int argc, const char **argv) {
dmn=new daemonprocess();
// set up signal handlers for clean shutdown
dmn->handleShutDown((RETSIGTYPE *)shutDown);
dmn->handleCrash((RETSIGTYPE *)shutDown);
// change the user/group that the daemon is running as
dmn->runAsUser("nobody");
dmn->runAsGroup("nobody");
// make sure that only one instance is running
int pid=dmn->checkForPidFile("/tmp/dmn.pidfile");
if (pid>-1) {
printf("Sorry, an instance of this daemon is already running with process id: %d\n",pid);
delete dmn;
exit(0);
}
// detach from the controlling terminal
dmn->detach();
// create a pid file which is used to make sure that only one instance
// is running and can also be used to kill the process
dmn->createPidFile("/tmp/dmn.pidfile",permissions::ownerReadWrite());
if (!fork()) {
for (;;) {
printf("%d: child looping...\n",
process::getProcessId());
snooze::macrosnooze(1);
}
}
// loop, printing "looping..." once per second
for (;;) {
printf("%d: parent looping...\n",
process::getProcessId());
snooze::macrosnooze(1);
}
}
刚一运行a.out奶奶的报错:难怪sqlrelay老是很多麻烦,呵呵
[root@localhost sqlrelay]# ./a.out
./a.out: error while loading shared libraries: librudiments-0.32.so.1: cannot open shared object file: No such file or directory
./a.out: error while loading shared libraries: librudiments-0.32.so.1: cannot open shared object file: No such file or directory
解决步骤:
1、vi /etc/ld.so.conf.d/fuse.conf (新增一个文件)
写入:/usr/local/rudiments/lib( librudiments-0.32.so.1所在位置)
2、ldconfig(重新载入系统)
[root@localhost sqlrelay]# ./a.out
17526: child looping...
17525: parent looping...
[root@localhost sqlrelay]# 17526: child looping...
大功告成!
这样指定也可以:
g++ test.cpp -I/usr/local/rudiments/include/ -L/usr/local/rudiments/lib -lrudiments
更多相关编程,参考如下网站:
来源:
http://rudiments.sourceforge.net/rudiments/programming/baseclasses.html#daemon
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/3061/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2010-5-12 17:38
评论列表