This post lists a few examples to check the status of your system in macOS and Linux

Generic

Note: The definition of 'generic' is eligible to be executed in any *nix system.

List Specified Informations by Process Id

$ ps -p 30314,27363,30019 -o pid,uid,user,args --sort user
  PID   UID USER     COMMAND
30019   996 nginx    php-fpm: pool www
30314   996 nginx    php-fpm: pool www
27323     0 root     [kcopyd]

Find Process By Port

$ sudo lsof -i:80
COMMAND   PID  USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   10293  root    8u  IPv4 43576165      0t0  TCP *:http (LISTEN)
nginx   20010 nginx    8u  IPv4 43576165      0t0  TCP *:http (LISTEN)
nginx   20011 nginx    8u  IPv4 43576165      0t0  TCP *:http (LISTEN)
nginx   20012 nginx    8u  IPv4 43576165      0t0  TCP *:http (LISTEN)
nginx   20013 nginx    8u  IPv4 43576165      0t0  TCP *:http (LISTEN)

macOS

Get Total Memory

$ sysctl hw.memsize
hw.memsize: 17179869184

Get CPU Brand String

$ sysctl machdep.cpu.brand_string
machdep.cpu.brand_string: Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz

Get CPU Count

$ sysctl hw.ncpu
hw.ncpu: 8

Linux

Get Total Memory

$ cat /proc/meminfo  | grep MemTotal
MemTotal:        8162256 kB

Get CPU Brand String

$ cat /proc/cpuinfo  | grep 'model name' | uniq -c
      4 model name  : Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz
$ cat /proc/cpuinfo  | grep 'model name' | uniq
model name  : Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz

Get CPU Count

$ cat /proc/cpuinfo  | grep 'model name' | wc -l
4
Categories: Code

Yu

Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

Leave a Reply

Your email address will not be published. Required fields are marked *