Lao Li share: "Linux shell Script Raiders" essentials (eight)

Source: Internet
Author: User

1. Printing process [[email protected] program_test]# PS-E | Head
PID TTY Time CMD
1? 00:00:03 Init
2? 00:00:00 Kthreadd
5 y 00:00:00 migration/0
6} 00:00:00 ksoftirqd/0
3 y 00:00:00 migration/0
4} 00:00:00 watchdog/0
7? 00:00:00 events/0
8? 00:00:00 Cgroup
9? 00:00:00 Khelper 2, top CPU-intensive process list [[email protected] program_test]# Top

Top-23:45:17 up 1:12, 5 users, Load average:0.00, 0.00, 0.00
tasks:153 Total, 1 running, 143 sleeping, 9 stopped, 0 zombie
Cpu (s): 0.3%us, 0.3%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.3%hi, 0.0%si, 0.0%st
mem:1030528k Total, 377184k used, 653344k free, 32588k buffers
swap:2064376k Total, 0k used, 2064376k free, 170968k cached

PID USER PR NI VIRT RES SHR S%cpu%MEM time+ COMMAND
4429 Root 0 2704 1140 880 R 0.7 0.1 0:00.12 Top
Root 0 0 0 0 S 0.3 0.0 0:01.63 ata_sff/0
2462 yy 0 73100 23m 18m S 0.3 2.3 0:12.11 VMTOOLSD
1 Root 0 2900 1436 1212 S 0.0 0.1 0:03.10 Init

3. List the processes that account for the most CPUs [[email protected] program_test]# Ps-eo comm,pcpu--sort-pcpu | Head
COMMAND%CPU
Xorg 0.5
VMTOOLSD 0.2
VMTOOLSD 0.2
init 0.0
Kthreadd 0.0
migration/0 0.0
ksoftirqd/0 0.0
migration/0 0.0
watchdog/0 0.0 4, print out bash progress corresponding Pid[[email protected] program_test]# ps-c bash-o pid=
2624
2650
2696
2732
2759
3842
Equivalent to the following command [[email protected] program_test]# Ps-aux | grep Bash | awk ' BEGIN {fs= ' "} $11==" Bash "{print $} '
Warning:bad syntax, perhaps a bogus '-'? See/usr/share/doc/procps-3.2.8/faq
2624
2650
2759 5, enumerate the signals used: [[email protected] program_test]# kill-l
1) SIGHUP 2) SIGINT 3) Sigquit 4) Sigill 5) SIGTRAP
6) SIGABRT 7) Sigbus 8) SIGFPE 9) SIGKILL) SIGUSR1
One) (SIGSEGV) (SIGUSR2) sigpipe) sigalrm) SIGTERM
Sigstkflt) (SIGCHLD) Sigcont SIGSTOP) SIGTSTP
(Sigttin) Sigttou () Sigurg) sigxcpu) Sigxfsz
(SIGVTALRM) sigprof) sigwinch SIGIO) SIGPWR
Sigsys) (sigrtmin) sigrtmin+1) sigrtmin+2 Notoginseng) sigrtmin+3
sigrtmin+4) sigrtmin+5 (sigrtmin+6) sigrtmin+7) sigrtmin+8
sigrtmin+9) (sigrtmin+10) sigrtmin+11 () sigrtmin+12) sigrtmin+13
(sigrtmin+14) sigrtmin+15 () SIGRTMAX-14) SIGRTMAX-13) SIGRTMAX-12
SIGRTMAX-11) SIGRTMAX-10 SIGRTMAX-9) SIGRTMAX-8 () SIGRTMAX-7
(SIGRTMAX-6) SIGRTMAX-5) SIGRTMAX-4 () SIGRTMAX-3) SIGRTMAX-2 6, Common signal 1) SIGHUP 1--suspend detection of the control process and terminal; 2) SIGINT 2--Press CTRL + C to send a signal 3) SIGKILL 9--strong kill Process 4) SIGTERM 15--default to terminate process 5) SIGTSTP 20--Press CTRL + Z to send a signal 7, kill process by process name [email protected] ~]$ Killall-9 su
Su:no process killed 8, capturing and responding to a signal test trap

[email protected] ~]$ Cat singlehandle.sh | Sed '/^$/d '
#!/bin/bash
function handler ()
{
Echo Hey, received Signal:sigint
}
echo My Process ID is $$
Trap ' handler ' SIGINT
While true;
Do
Sleep 1
Done

9, which//find the location of a command Whereis//not only return the path of the command, but also print out the corresponding command manual location file//Determine the file type Whatis//output as a parameter command short information uptime//system can run the total number of processes flat Mean 10, hostname//Get host name//get partition info [[email protected] ~]$ cat/proc/partitions
Major Minor #blocks name

8 0 20971520 SDA
8 1 307200 sda1
8 2 18598912 Sda2
8 3 2064384 Sda3

Lao Li share: "Linux shell Script Raiders" essentials (eight)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.