You can always see how the kernel does it. You will see the function:
proc_pid_cmdline(struct task_struct *task, char * buffer)
It's quite simple, but if you have one task_structfor the process you are interested in, you use access_process_vm()to cut the bits you need with mm->arg_start.
source
share