Linux内核模块获取自身路径,从内核linux中获取pid的完整进程路径

我正在为我的设备构建自定义内核linux(如嵌入式设备)。我想记录杀死系统调用的所有信息。所以我在kill系统调用中修改代码并获得pid来杀死。但是我无法获得完整的流程路径,我刚刚获得当前流程的完整路径。 这是我从pid获取进程路径的代码。从内核linux中获取pid的完整进程路径

long GetProcessPathFromPid(const pid_t p_id, char* pszProcessPath, int iSize)

{

struct task_struct *task = NULL;

struct pid *pid_struct = NULL;

struct mm_struct *mm = NULL;

//struct file *exe_file = NULL;

//char buf[256] = {0};

//char *result = ERR_PTR(-ENOENT);

//int iResultLength = 0;

pid_struct = find_get_pid(p_id);

if (pid_struct == NULL)

{

printk("Fail to find_get_pid.\n");

}

task = pid_task(pid_struct, PIDTYPE_PID); // Get task_struct

if (task == NULL)

{

printk("Fail to pid_task.\n");

}

mm = get_task_mm(task); // Get mm of task_struct

mmput(mm);

printk("Finish hook kill process\n.");

return 0; // Get mm of task_struct

}

当我更新固件,这是错误:

Call Trace:

[<8042971c>] printk+0x24/0x30

[<800c37c8>] GetProcessPathFromPid+0x38/0x88

[<800c3b60>] LogKillProcess+0x64/0xf4

[<800443d4>] sys_kill+0x30/0x1d8

[<800354b0>] do_wait+0x11c/0x220

[<8042e234>] wait_for_completion_killable+0x18/0x30

[<80043a3c>] set_current_blocked+0x30/0x48

[<>] repair_env_string+0x0/0x94

[<8003664c>] sys_wait4+0x80/0xfc

[<800344d8>] child_wait_callback+0x0/0x8c

[<>] repair_env_string+0x0/0x94

[<8001b59c>] stack_done+0x20/0x40

[<800b07a8>] sys_close+0x0/0x158

[<>] repair_env_string+0x0/0x94

Call Trace:

[<8042fe88>] _raw_spin_lock+0x10/0x3c

[<8002ef68>] get_task_mm+0x20/0x7c

[<800c37c8>] GetProcessPathFromPid+0x38/0x88

[<800c3b60>] LogKillProcess+0x64/0xf4

[<800443d4>] sys_kill+0x30/0x1d8

[<8001b59c>] stack_done+0x20/0x40

Code: 24630001 af830014 3c020001 00622821 e0850000 10a0fffc 00032c02 3063ffff

pe=GPON

---[ end trace aee100dae37dfc66 ]---

note: init[1] exited with preempt_count 1

FinWLmngr Daeish hook kill process

.mon is running

!!!! PLL locked !!!!!! !!!! RX CDR locked !!!!!! !!!! TX CDR locked !!!!!! GPON BEN Calibration Done

GPON SerDes Initialization Sequence Done

Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b

你能帮助我吗?谢谢!

2017-03-25

rum

+0

什么是错误信息(如果失败)?什么是pid?内核中有代码生成'/ proc/$ PID/exe'链接:http://lxr.free-electrons.com/source/fs/proc/base.c?v=4.8#L1556 fs/proc/base.c'proc_exe_link' - 使用'get_proc_task' /'get_task_exe_file' /'path_get'。 –

+1

这不检查。你得到一个错误的可执行文件路径,还是你的内核恐慌? –

+0

我无法使用该功能查找完整路径过程,但我找到了解决此问题的方法。感谢您的支持! –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值