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 在此某人载过跟头
相关文档:
引自:http://server.it168.com/a2009/0309/267/000000267930.shtml
4.3 Linux进程管理命令详解(1)
Linux管理进程的最好方法就是使用命令行下的系统命令。Linux下面的进程涉及的命令有at, bg, fg, kill, crontab, jobs, ps, pstree, top, nice, renice, sleep, nohup。
1.at命令:定时运行命令
作用: ......
Windows系统其实和Linux系统有相似的地方,Windows系统文件、目录的属性有只读、隐藏,而Linux也一样。 Linux中,每一个文件都具有特定的属性。主要包括文件类型和文件权限两个方面。可以分为5种不同的类型:普通文件、目录文件、链接文件、设备文件和管道文件。 所谓的文件权限,是指对文件的访问权限,包括对 ......
会员下载:
http://vipdown.3800hk.com/jiaocheng/linux/linux/@LinkGate@12403487266409x1196776239x12403488007143-5740071909166dc778c8b9deb5c6b4cc@LK@/01.rar
http://vipdown.3800hk.com/jiaocheng/linux/linux/@LinkGate@12403487266409x1196776239x12403488007143-177072d80fd416c4134c7 ......