Command Line

4. Job Control

2020-03-17 08:00 CST
2020-03-18 13:27 CST
[![Creative Commons License](https://i.creativecommons.org/l/by-nc/4.0/88x31.png)](http://creativecommons.org/licenses/by-nc/4.0/)

Jobs Control

sleep 20 # seconds
man signal
#ctrl+c SIGINT
#ctrl+\ SIGQUIT
#ctrl+z SIGSTOP
nohup ./run.sh &
jobs # show jobs background
bg %1 # continue to run
fg %2
kill -STOP %1
kill -HUP %1
kill -KILL %2

C signal

#include <signal.h>
#include <stdint.h>
void signal\_callback\_handler(int signum) {
  printf("         TERMINATED         \n");
  setBufferedInput(true);
  printf("\033[?25h\033[m");
  exit(signum);
}
int main(){
  signal(SIGINT, signal\_callback\_handler);
}

Python signal

#!/usr/bin/env python
import signal, time
def handler(signum, time):
	print("\nI got a SIGINT, but I am not stopping")

signal.signal(signal.SIGINT, handler)
i = 0
while True:
	time.sleep(.1)
	print("\r{}".format(i), end="")
	i+=1

Multiplexes

tmux # Sessions - Windows - Panes
tmux ls

Remote

ssh-keygen
ssh-copy-id -i .ssh/id\_rsa.pub zzw@example
ssh zzw@example ls -a
scp notes.md zzw@example:~/notes.md
rsync -avP SRC [USER@]host:DEST

System Deamon

  • systemd on Linux
  • launchd on Macos
  • sysctl
  • lauchctl