in linux, Tutorials

I administrate linux servers from time to time, and a common need in those situation is monitoring what a different terminal is doing. Either because of a lost connection to an SSH terminal which runs a command, or wanting to know what an unrecognized terminal is doing. To that end I use a very useful tool called strace.

Strace is a system utility on linux systems that can trace all systems calls and signals that a process uses. To monitor a terminal we can make strace print all occurrences of the read and write system calls that the terminal process is using.

Note: This tutorial assumes you have root privileges otherwise you won't be able to use strace to connect and monitor a running process.

To see who’s connected to the machine we can list /dev/pts. The directory contains special character files for each connected pts.

To use strace for the task at hand, we first need to identify the terminal we want to connect to. We can use ps which lists all the running processes like so:

alpha@milkyway:~$ ps aux | grep pts
alpha      943  0.0  0.0  44472  3344 pts/4    R+   09:23   0:00 ps aux
alpha      944  0.0  0.0  21536  1048 pts/4    S+   09:23   0:00 grep --color=auto pts
alpha     7978  0.0  0.0  29812  5172 pts/3    Ss+  09:16 0:00 bash
alpha    22659  0.0  0.0  29812  5192 pts/0    Ss   00:13   0:00 bash
root     22877  0.0  0.0  72716  4304 pts/0    S    00:24   0:00 sudo su alchemist
root     22878  0.0  0.0  72248  3884 pts/0    S    00:24   0:00 su alchemist
alchemi+ 22891  0.0  0.0  29808  5100 pts/0    S+   00:24   0:00 bash
alpha    23022  0.0  0.0  29812  5104 pts/1    Ss   00:28   0:00 bash
root     23034  0.0  0.0  72956  4424 pts/1    S    00:28   0:00 sudo su
root     23035  0.0  0.0  72248  3780 pts/1    S    00:28   0:00 su
root     23049  0.0  0.0  28712  3924 pts/1    S+   00:28   0:00 bash
alpha    24095  0.0  0.0  29812  5144 pts/2    Ss+  01:15   0:00 bash

To see all the input and output of the pts we’re interested in we can call strace with the following arguments:

strace -f -s999 -e trace=write -p 7978

-f: This option tells strace to follow the system calls for the child processes as well (commands run in the terminal).

-s: by default strace truncates strings, we can set the truncate limit higher so we can see more of the output.

-e trace=write: the system calls we want to monitor. For our task we only want to see the output in the terminal. If you want to log what the user types you can add the read call as well. The format is trace=syscalls1,syscall2,..

-p: The pid of the process we’re monitoring.

 

The output is useful, but it would be more useful if the output was more human suitable. You’re in luck, I wrote a simple wrapper to make the output appear like a normal terminal. You can download it from here.

Write a Comment

Comment

Webmentions

  • get dissertation help

    writing dissertation aims and objectives https://helpon-doctoral-dissertations.net/

  • professional dissertation writing

    thesis and dissertation https://dissertations-writing.org/

  • write my dissertation uk help i can

    dissertation proposal sample https://mydissertationwritinghelp.com/

  • dissertation chapters

    thesis dissertation writing services https://help-with-dissertations.com/

  • dissertation writing services uae

    online cheap dissertation help https://dissertationwriting-service.com/

  • dissertation writing service

    help with completing dissertation https://buydissertationhelp.com/

  • hollywood4fun slots

    slots inferno https://slotmachinegameinfo.com/

  • wizard of oz slots

    myvegas slots facebook https://www-slotmachines.com/

  • nasty slots

    online slots real money https://411slotmachine.com/

  • reel deal slots

    igt slots https://download-slot-machines.com/

  • common expansion slots

    how to win at slots https://beat-slot-machines.com/

  • my vegas slots

    ff7 cait sith slots limit https://slot-machine-sale.com/

  • son and moon slots

    triple diamond slots https://slotmachinesforum.net/

  • las vegas world slots free

    play free bonus slots https://slotmachinesworld.com/

  • innovative slots

    free classic slots https://pennyslotmachines.org/

  • vegas downtown slots

    free slots for pc https://candylandslotmachine.com/

  • scatter slots by murka

    888 free slots machine https://freeonlneslotmachine.com/

  • slots free online

    slots of vegas casino https://2-free-slots.com/

  • gay dating fargo nd

    gay dating online https://speedgaydate.com/

  • local gay sex chat

    transcript of a man’s first gay chat https://gay-buddies.com/

  • local gay chat rooms

    chicago gay chat rooms free https://gaytgpost.com/

  • gay bear dating sites

    torrington ct gay dating https://gaypridee.com/

  • dirty gay sex chat

    gay chat aveneu https://bjsgaychatroom.info/

  • gay dating sites yahoo answers

    single gay dating site https://gaysugardaddydatingsites.com

  • gay dating search for free

    dinner for eight gay dating https://gayfade.com

  • fat chub gay dating

    chubby gay mens dating sites https://speedgaydate.com

  • boomerang gay dating

    feminine gay dating sites https://gayprideusa.com

  • college gay dating site

    gay dating app for over 50 https://gay-buddies.com

  • gay dating sites for kids 10-14

    gay addiction dating apps https://gaypridee.com

  • 2warship

    1vibrators