|
- //linux获得cmdline字符串,linux取得cmdline
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- int get_cmd_line_from_proc(char *cmdBuffer)
- {
- FILE *pfile;
- pfile = popen("cat /proc/cmdline", "r");
- if(pfile != NULL){
- fgets(cmdBuffer, 2046, pfile);
- return 0;
- }else{
- return -1;
- }
- }
- int main(int argc, char *argv[])
- {
- char cmdline[2048];
- memset(cmdline, 0, sizeof(cmdline));
- if(0 != get_cmd_line_from_proc(cmdline))
- {
- printf("get cmdline error!.\n\r\n");
- return -1;
- }
- printf("CMDLINE: %s .\n\r\n", cmdline);
- return 0;
- }
复制代码 |
|