0

I'm trying to get the cmdline of a process as it is shown in /proc/$PID/cmdline by it's PID from within Kernel Context.

I can access the task_struct and it's field "comm", which however only holds 16 characters.

What is the best way to achieve this?

I'm using the AOSP Wahoo Kernel

( repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-wahoo-4.4-pie-qpr2 )

  • 1
    Look at the source of `/proc/$PID/cmdline` handler. Perhaps it will shed a light how to achieve this. https://elixir.bootlin.com/linux/v5.6-rc1/source/fs/proc/base.c#L357 – 0andriy Feb 14 '20 at 16:29
  • @0andriy OP is specifically talking about the Android kernel, you can't assume that it uses the same API as the standard Linux kernel. – Marco Bonelli Feb 17 '20 at 20:21
  • @MarcoBonelli, so what? Internal API in kernel is being changed from version to version. The OP has to look at that example to conduct further research. That's why I put my stuff as a comment and not as a full featured answer. If you are going to answer, please, take this into consideration. – 0andriy Feb 17 '20 at 21:19
  • @0andriy I was referring to your link, doesn't make much sense to look there. – Marco Bonelli Feb 17 '20 at 21:55
  • @MarcoBonelli, Ah, have you ever looked at the Android kernel source code? Have you seen drastic changes there (in the area of cmdline handling)? Something is telling me that answers to above are **no** and **no**. Otherwise, write your best answer and I will vote it up! – 0andriy Feb 17 '20 at 21:59
  • @MarcoBonelli JFYI: https://android.googlesource.com/kernel/goldfish/+/refs/heads/android-goldfish-3.10-n-dev/fs/proc/base.c#203 vs. https://elixir.bootlin.com/linux/v3.10.108/source/fs/proc/base.c#L203 And please, don't tell that there is no sense to look at the upstream. – 0andriy Feb 17 '20 at 22:11
  • @0andriy I'm not saying that there is no sense. I'm just saying that that's probably not where you should look specifically. There's no guaranteed compatibility of internal APIs between the two. Why not just link the first one in the first place? That's the point I was trying to make. – Marco Bonelli Feb 17 '20 at 22:13
  • 1
    @0andriy In fact I had looked at the Kernel sources before. Like MarcoBonelli said the Android source is quite different. Unfortunately in Android Kernel this is not done that straight forward ( because in your link it ist basically just a call to get_task_cmdline() , which I would have been able to sort out myself. ) The proc read handler function for cmdline in the wahoo sources has about 200 lines and does a lot of stuff, which I don't understand because I'm completely new to kernel developement https://github.com/android-linux-stable/wahoo/blob/android-msm-wahoo-4.4/fs/proc/base.c – killa-pixel Feb 21 '20 at 13:46
  • @MarcoBonelli As building a Kernel for an embedded device and reflashing it each time is quite cumbersome (if you dont't know exactly what you're doing and have to trial and error), I was hoping to get some advice here first. But thank you anyway. – killa-pixel Feb 21 '20 at 13:46
  • Oh, please. I just run a diff between v4.4.168 and file you are referring to. There are no changes in the area you are talking about. @MarcoBonelli simple tries to find an argument in his support, where there is none. – 0andriy Feb 21 '20 at 13:53
  • Yes, you have to go into guts of MM in the Linux kernel to get what you want to. So, 200 LOCs is not too many. – 0andriy Feb 21 '20 at 13:55
  • @0andriy My bad. Actually the big difference is not between android and upstream, but between v4.4 and the version you posted. – killa-pixel Feb 21 '20 at 14:39

0 Answers0