易截截图软件、单文件、免安装、纯绿色、仅160KB

linux 程序内部 查看可执行程序路径

linux shell pwd 显示当前路径
假若有test.cpp
g++ test.cpp -o test
./test
想在test中找到当前执行程序所在的路径
可以再test.cpp中使用readlink函数
具体见如下实例:
#include<iostream>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<string>
using namespace std;
int main()
{
 char buff[1024];
 memset(buff,0,sizeof(buff));
 int n = readlink("/proc/self/exe",buff,1023);
 if(n<0)
 {
  cout<<"Get Path failed"<<endl;
  return -1;
 }
 string path = buff;
 int nLen = path.rfind('/');
 path.erase(nLen,path.length() - nLen);
 cout<<"zui zhong lu jing :"<<path<<endl;
 
 return 0;
}
谨记是/proc/self/exe 在此某人载过跟头


相关文档:

实战Linux Bluetooth编程 (七) SDP协议

Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......

linux下共享内存(shm)使用示例

#include <sys/ipc.h>
#include <stdio.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#define PERM IPC_CREAT //S_IRUSR|S_IWUSR
#include <errno.h>
int main(int argc,char **argv)
{
int shmid[2048];
c ......

linux下统计时间类

class CTimeTickCount
{
public:
CTimeTickCount(int threadIndex, int id )
{
struct timezone tz;
gettimeofday(&m_tvStartTime, &tz);
// m_tmStartTime = ACE_OS::gettimeofday();
m_iThreadIndex ......

Linux设备驱动编程之阻塞与非阻塞

阻塞操作是指,在执行设备操作时,若不能获得资源,则进程挂起直到满足可操作的条件再进行操作。非阻塞操作的进程在不能进行设备操作时,并不挂起。被挂起的进程进入sleep状态,被从调度器的运行队列移走,直到等待的条件被满足。
  在Linux
  关于上述例程,我们补充说一点,如果将驱动程序中的read函数改为:
stat ......

Linux学习笔记零零三

存储管理
MMU与内核内存管理的关系
从线性地址到物理地址的映射,通过页目录表和页表来实现的。
内核为存储管理维护了一套复杂的数据结构,页目录表和页表是主要的结构之一。这些表也是存储在物理内存页面中的,因此,也是以4K为单位。
表中的每个表项都记录了一个32位的地址,为4个字节,因此,一个表中最多可以有1K项 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号