linuxÔõôÉó²éÀú³ÌµÄ·¾¶
¿ÉÒÔʹÓÃÒÔϼ¸ÖÖÒªÁìÔÚ linux ÖÐÉó²éÀú³ÌµÄ·¾¶£ºps -p pid -o comm,argslsof -p pidcat /proc/pid/cwd
ÔõÑùÔÚ Linux ÖÐÉó²éÀú³ÌµÄ·¾¶
Linux ϵͳÌṩÁ˶àÖÖÒªÁìÀ´Éó²éÕýÔÚÔËÐеÄÀú³ÌµÄ·¾¶¡£ÒÔÏÂÏÈÈݼ¸ÖÖ¼òÆÓ¶øÓÐÓõÄÏÂÁ
1. ps ÏÂÁî
ps ÏÂÁî¿ÉÒÔÏÔʾÕýÔÚÔËÐеÄÀú³ÌÐÅÏ¢£¬°üÀ¨Â·¾¶¡£Ê¹ÓÃÑ¡Ïî -p Ö¸¶¨Àú³Ì ID£¬Ñ¡Ïî -o Ö¸¶¨ÒªÏÔʾµÄ×ֶΡ£
ps -p PID -o comm,args
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ps -p 1234 -o comm,args /bin/bash /home/user/script.sh
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁÏÔʾÀú³Ì ID Ϊ 1234 µÄÀú³ÌµÄ·¾¶£¨/bin/bash£©ºÍ²ÎÊý£¨/home/user/script.sh£©¡£
2. lsof ÏÂÁî
lsof ÏÂÁî¿ÉÒÔÏÔʾ·¿ªµÄÎļþºÍÀú³ÌµÄÏà¹ØÐÅÏ¢£¬°üÀ¨Â·¾¶¡£Ê¹ÓÃÑ¡Ïî -p Ö¸¶¨Àú³Ì ID¡£
lsof -p PID
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
lsof -p 1234 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 1234 user cwd DIR 11,0 58543 /home/user bash 1234 user rtd DIR 11,0 58543 /home/user/.config bash 1234 user txt REG 8,1 2176876 58658 /home/user/script.sh
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁÏÔʾÀú³Ì ID Ϊ 1234 µÄÀú³Ì·¿ªµÄËùÓÐÎļþ£¬°üÀ¨¿ÉÖ´ÐÐÎļþ£¨/home/user/script.sh£©¡£
3. procfs
procfs ÊÇÒ»¸öÐéÄâÎļþϵͳ£¬ÌṩÓйØϵͳºÍÀú³ÌµÄÐÅÏ¢¡£ÒªÉó²éÀú³ÌµÄ·¾¶£¬¿ÉÒÔ»á¼ûÒÔÏÂÎļþ£º
/proc/PID/cwd
µÇ¼ºó¸´ÖÆ
ÆäÖÐ PID ÊÇÀú³Ì ID¡£
ʹÓà cat ÏÂÁî¿ÉÒÔ¶ÁÈ¡ÎļþµÄÄÚÈÝ£¬»ñÈ¡Àú³ÌµÄ·¾¶¡£
cat /proc/PID/cwd
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
cat /proc/1234/cwd /home/user
µÇ¼ºó¸´ÖÆ
¸ÃÏÂÁÏÔʾÀú³Ì ID Ϊ 1234 µÄÀú³ÌµÄÊÂÇéĿ¼£¨/home/user£©¡£
ÒÔÉϾÍÊÇlinuxÔõôÉó²éÀú³ÌµÄ·¾¶µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡