compsci-missing_semester_2020/_subsections/lesson-05.org
2025-07-21 00:56:00 +03:00

5.1 KiB
Executable file

Lesson 05 | Command line Environment

notes

topics

  • job control
  • terminal multiplexers
  • dot files / how to configure
  • work with remote machines

job control

sleep

  • puts process to sleep for a specified amount of time
  • exit by typing Ctrl-C

Ctrl-C

  • sends SIGINT - signal interrupt
  • man signal will show the list of signals

signals

SIGQUIT
signal sent when we want to quit
SIGTERM
similar to quit but not in term
SIGHUP
when we have processes running but still want to close

pausing

SIGSTOP
pause execution of program
SIGCONT
continue program

python library

  • use import signal
import signal
def handler(signum, frame):
    printf("signal received")

signal.signal(signal.SIGINT, handler)
  • the above would catch a Ctrl-C and run it through handler
  • you use this by catching a Ctrl-C and running any saves or cleanup before exiting

nohup and jobs

  • allows for a process to continue livign when the terminal is killed

example

  • sleep put the process to sleep
  • '&' puts the process in the background

    • wont take over the process
nohup sleep 2000 & python somprog.py

jobs

  • jobs

will show the suspended and running processes in background

  • how to restart a suspended process

    • type 'jobs' to see what there is in this terminal
    • the find the jobs number, ie [1] or [2]
    • use the 'bg' command

      bg %1

kill command

  • allows you to send any kind of signal to a job
  • e.g. "stop" will suspend but not close the job

some commands

HUP
Hang Up
STOP
suspend
KILL
kill it no matter what

Terminal Multiplexer

overview

  • tmux
  • lets you create workspaces that you can work in
  • rearrange the environment
  • have different settings

core concepts

  • hierarchy

    • sessions
    • windows
    • panes

dot files

alias

  • remap a source series of characters to a longer series
  • alias takes a single argument, ie, do not use spaces
  • to show what an alias refers to pass the alias to the alias command

    • e.g.
~/somedirectory >>> alias myaliasedcommand
myaliasedcommand='ls -lah'
examples
  • make an alias "ll" for a list command with flags
alias ll="ls -lah"
  • make an alias for git status
alias gs="git status"
  • alias to prompt for an override
alias mv="mv -i"

text based configuration 'dot files'

  • called 'dot files' because they start with a dot

    • .bashrc

      • must be in the home directory
    • PS1

      • prompt variable for your prompt
      • you can set it in the .bashrc file
      • PS1=" >> "
    • .vimrc

      • vim configuration file

terminal emulator