Skip to content

Instantly share code, notes, and snippets.

@jimathyp
Last active August 4, 2020 20:15
Show Gist options
  • Select an option

  • Save jimathyp/e4c07ea2ce0034d6087e17c17a959ebb to your computer and use it in GitHub Desktop.

Select an option

Save jimathyp/e4c07ea2ce0034d6087e17c17a959ebb to your computer and use it in GitHub Desktop.
LInux Sysadmin

Linux sysadmin

Login as a user

sudo -u postgres -i

Process with memory leak?

eg. aws-vault

$ aws-vault exec profile-name -- aws s3 ls 
aws-vault: error: exec: Error execing process: cannot allocate memory

Check free -h

Run

ps -rss -er rss,pid,command --sort

# r only running processes
# s 
# e all processes

# rss resident set size  (non-swapped physical mem that a task has used)
# pid process ID
# command (only the executable name)

# some differences with GNU --sort, BSD etc

Or system has run out of file handles, or socket buffers, and has lots of memory left.

strace

simplest, trace all system calls (sudo strace..)

strace df -h 

output something like

open(....) = 3

open (the system call) (...) some file and mode 3 the system call return value

can strrace a running pid

strace -p some_pid

(then Ctrl C)

To get relative timestamps, -r Prefix with clock time, -t Prefix with clock time, -tt Prefix with clock time, -ttt

use -c flag to get cumulative times for each call

strace -c -p somepid

Can get instruction points, -i

To get command time, time spent in system calls, (start, end times) -T

Can filter on specific system calls -e trace=write -e trace=process -e trace=file -e trace=memory -e trace=network -e trace=signal

Redirect output -o some_file.txt

System calls

Futex. fast userspace mutex. kernel system call. used to implement basic locking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment