读proc/pid得到进程名称
2009-11-05 11:23
513 查看
#include <stdio.h>
#include <stdlib.h>
#include <sys/procfs.h>
#include <memory.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stropts.h>
void get_program_name( char *p_name_space ){
char strBuf[100];
memset( strBuf, 0, sizeof( strBuf));
sprintf( strBuf, "/proc/%d/psinfo", getpid());
int fd = open( strBuf, O_RDONLY);
if( fd == -1 ){
printf("open err!");
}
psinfo_t retval;
read(fd, &retval, sizeof(psinfo_t));
char p_name[1024] = "";
sprintf( p_name, "%s", retval.pr_fname );
char *p_name_begin = strchr( p_name, '/');
close(fd);
strcpy( p_name_space, p_name_begin + 1 );
}
int main(){
char p_name[1024] = "";
get_program_name( p_name );
printf("proc name :%s/n", p_name );
return 0;
}
#include <stdlib.h>
#include <sys/procfs.h>
#include <memory.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stropts.h>
void get_program_name( char *p_name_space ){
char strBuf[100];
memset( strBuf, 0, sizeof( strBuf));
sprintf( strBuf, "/proc/%d/psinfo", getpid());
int fd = open( strBuf, O_RDONLY);
if( fd == -1 ){
printf("open err!");
}
psinfo_t retval;
read(fd, &retval, sizeof(psinfo_t));
char p_name[1024] = "";
sprintf( p_name, "%s", retval.pr_fname );
char *p_name_begin = strchr( p_name, '/');
close(fd);
strcpy( p_name_space, p_name_begin + 1 );
}
int main(){
char p_name[1024] = "";
get_program_name( p_name );
printf("proc name :%s/n", p_name );
return 0;
}
相关文章推荐
- 通过/proc/pid./status查看进程信息
- Linux修改进程名称(setproctitle())
- bat 批处理 开始进程 得到pid 杀死进程 计算器
- 由PID得到进程名
- linux进程监控脚本(/proc/$pid/status)
- cat /proc/$PID/status进程状态
- Linux修改进程名称(setproctitle())
- SNMP阶段总结,基于SNMP++提取进程内存使用,CPU占用率,进程名称,PID,路径等信息的功能函数,生成了DLL,源码送上
- 查看进程状态/proc/pid/stat
- 进程PID取窗口句柄+进程名称取PID
- 如何在命令行(cmd)通过TCP/IP端口(port)查询所在的进程号(pid)或进程名称,并终止该进程
- 查看进程状态/proc/pid/stat
- linux /proc/pid进程信息说明
- 通过 /proc/[pid]/ 查看进程状态
- 嵌入式 一个进程获取另一个指定名称进程的PID
- 假如想自己写软件的话,可以先FindWindow找到那个窗口的句柄,然后用GetWindowThreadProcessId就可以得到这个窗口的进程ID和线程ID,有了这些ID就可以找到进程名称了。
- /proc/pid进程相关说明
- [No0000CB]如何在命令行(cmd)通过TCP/IP端口(port)查询所在的进程号(pid)或进程名称,并终止该进程
- 得到父进程的PID
- Linux下C语言开发(已知进程名得到其PID号)