Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道如何用 C 替换变量的值。
execl ("/bin/cat","cat","/proc/30828/status", (char *)0 );
我希望能够将“30828”更改为变量,因为这个值不是固定的。我想知道是否可以在 SHELL 中进行类似的操作。例如在 shell 中你可以这样做:
K=`ls -lis $i` echo $K
用于snprintf()将 PID 替换为字符串变量:
snprintf()
char statusfile[30]; sprintf(statusfile, sizeof statusfile, "/proc/%d/status", pid); execl("/bin/cat","cat",statusfile, (char *)0 );