Thứ Ba, 1 tháng 12, 2020

Quản lý Process trong Solaris

Fuser -cu /s04 Check các process đang truy xuất vào vùng /s04
1. ĐN
- Process: là các tiến trình chạy service. Khi client kết nối đến mới hiển thị process qua lệnh
# ps -ef |grep "ssh"
# ps -ef |grep "ftp"

2. Monitoring hiệu năng
# prstat -a (chú ý xem process nào chiếm CPU, RAM cao, sắp xếp theo CPU
# prstat -s size --Order process theo size RAM
# prstat -Z --Tổng RAM, CPU cấp cho các tiến trình
# prstat -p 15771 // tải 1 process
Status:
a. Run
b. Sleep
c. Zombie: child
d. stop
3. Check process
# ps -ef |grep ora_     // Hiển thị các process bắt đầu bằng ora_
- Check chi tiết process
# pargs <process_id>
- Check đường dẫn chạy process
# pwdx <process_id>
- Check nội dung tiến trình đang chạy:
# ps eauwww 46465418 |grep TZ 
# /usr/ucb/ps auxvwww |grep java
pgrep pgrep -fl cron Check process ID với pattern cho trước
grep -l manager
Ptree
Pstop Stop process
Prun Chạy lại process
- Xác định PID, path, port
pfiles `ptree | awk '{print $1}'` | egrep '^[0-9]|port:' > 'filelog.txt'
4. Start/Stop process
pgrep rptpgm
pstop 3366
ps -ef |grep 3366
prun 3366
--KIll moi process ORACLE
root> ps -ef|grep $ORACLE_SID| \
      grep -v grep|awk '{print $2}'|xargs -i kill -9 {}  
root> ps -ef|grep LOCAL| grep -v grep|awk '{print $2}'|xargs -i kill -9 {}  
You can send the stderr and stdout to two different files using the below method. In this, it will not generate the nohup.out file at all.
 
1 root@instance-1:~# nohup ./script.sh > my-output 2> my-error &
2 [1] 4034
3 root@instance-1:/proc/4034/fd# ls -l
4 total 0
5 l-wx------ 1 root root 64 Nov  9 07:16 0 -> /dev/null
6 l-wx------ 1 root root 64 Nov  9 07:16 1 -> /root/my-output
7 l-wx------ 1 root root 64 Nov  9 07:16 2 -> /root/my-error
8 lr-x------ 1 root root 64 Nov  9 07:16 255 -> /root/script.s
 
You can also send both stdout and stderr to the same file of your interest other than nohup.out using the below method.
 
1 root@instance-1:~# nohup ./script.sh > my-output 2>&1 &
2 [1] 4178
3 root@instance-1:~#
4 root@instance-1:~#
5 root@instance-1:~# cd /proc/4178/fd
6 root@instance-1:/proc/4178/fd# ls -l
7 total 0
8 l-wx------ 1 root root 64 Nov  9 07:19 0 -> /dev/null
9 l-wx------ 1 root root 64 Nov  9 07:19 1 -> /root/my-output
10 l-wx------ 1 root root 64 Nov  9 07:19 2 -> /root/my-output
11 lr-x------ 1 root root 64 Nov  9 07:19 255 -> /root/script.sh
 
In the above command, 2>&1 indicates that both stdout and stderr should go to that file.
From <https://www.slashroot.in/nohup-command-tutorial-linux-example-usage> 
5. Kill process
- Kill theo string:
pgrep -l mail Hiển thị process ID, process name với pattern mail
pkill dtmail Kill theo tên process
- Kill theo PID:
Kill -9 <pid>
- Script Kill ProcessID
tmpfile=/flashrec/tmp.txt
sqlplus / as sysdba < < EOF
Set feedback off
coil $tmpfile
Select p.spid in v$ process p, v$ session s
where s.paddr = p.addr
and s.status = 'SNIPED';
spool off
EXPRESSIONS OF FOLKLORE
for x in ' cat $tmpfile | "grep" ^ [0123456789] ""
do
Kill-9 $x > / dev/null 2 > & 1
is
$tmpfile
From <https://www.eehelp.com/question/snipped-sessions-issue/> 

6. Các lệnh khác
-- Hiển thị cây theo process cha
# ptree -a

7. Thay đổi priotiry của process dùng nice hoặc renice
# renice -n 10 -p 4398  // Thay đổi process 4398 với priority 10
renice -n -8 -u David   // Thay đổi priority của user David là -8
Type the following command to display per-processor statistics; 12 seconds apart; 5 times
# mpstat 12 5
You can also use traditional ps and top command:
# top
# ps -e -o pcpu -o pid -o user -o args

8. Check process từ port
./pcp.sh -p 2233
root@sol11 # vi p2p.sh (old pcp.sh)
#!/usr/bin/ksh
#
# PCP (PID con Port)
# v1.08 30/12/2008 sam@unix.ms
#
# If you have a Solaris 8, 9 or 10 box and you can't
# install lsof, try this. It maps PIDS to ports and vice versa.
# It also shows you which peers are connected on which port.
# Wildcards are accepted for -p and -P options.
#
# Many thanks Daniel Trinkle trinkle@cs.purdue.edu
# for the improvements!
i=0
while getopts :p:P:a opt
do
case "${opt}" in
p ) port="${OPTARG}";i=3;;
P ) pid="${OPTARG}";i=3;;
a ) all=all;i=2;;
esac
done
if [ $OPTIND != $i ]
then
echo >&2 "usage: $0 [-p PORT] [-P PID] [-a] (Wildcards OK) "
exit 1
fi
shift `expr $OPTIND - 1`
if [ "$port" ]
then
# Enter the port number, get the PID
#
port=${OPTARG}
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep "port: $port$"`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\t$port\n$result"
echo "_________________________________________________________"
fi
done
elif [ "$pid" ]
then
# Enter the PID, get the port
#
pid=$OPTARG
# Print out the information
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | awk '/ptree/ {next} $1 ~ /^'"$pid"'$/ {print $1};'`
do
result=`pfiles $proc 2> /dev/null| egrep port:`
if [ ! -z "$result" ]
then
program=`ps -fo comm= -p $proc`
echo "$proc\t$program\n$result"
echo "_________________________________________________________"
fi
done
elif [ $all ]
then
# Show all PIDs, Ports and Peers
#
echo "PID\tProcess Name and Port"
echo "_________________________________________________________"
for proc in `ptree -a | sort -n | awk '/ptree/ {next} {print $1};'`
do
out=`pfiles $proc 2>/dev/null| egrep "port:"`
if [ ! -z "$out" ]
then
name=`ps -fo comm= -p $proc`
echo "$proc\t$name\n$out"
echo "_________________________________________________________"
fi
done
fi
exit 0

KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH: 📧 Mail: binhoracle@gmail.com ☎️ Mobile: 0902912888 ⚡️ Skype: tranbinh48ca 👨 Facebook: https://www.facebook.com/BinhOracleMaster 👨 Inbox Messenger: https://m.me/101036604657441 (profile) 👨 Fanpage: https://www.facebook.com/tranvanbinh.vn 👨 Inbox Fanpage: https://m.me/tranvanbinh.vn 👨👩 Group FB: https://www.facebook.com/groups/OracleDBAVietNam 👨 Website: http://www.tranvanbinh.vn 👨 Blogger: https://tranvanbinhmaster.blogspot.com 🎬 Youtube: http://bit.ly/ytb_binhoraclemaster 👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi 👨 Linkin: https://www.linkedin.com/in/binhoracle 👨 Twitter: https://twitter.com/binhoracle 👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội #OracleTutorial #OracleDBA #OracleDatabaseAdministration #học oracle database #oca #ocp #oce #ocm

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master