The script command makes a typescript of everything displayed on your terminal. This implementation demonstrates:
Usage: ft_script [options] [file]
Options:
-a Append to output file instead of overwriting
-c <command> Execute command instead of interactive shell
-q Quiet mode (suppress start/done messages)
-e Return exit status of child process
-f Flush output after each write (BONUS)
-h Display help and exit
- Fork: Creates child process
- Setsid: Child creates new session (becomes session leader)
- Open slave: PTY slave becomes controlling terminal
- Redirect I/O: stdin/stdout/stderr → PTY slave
- Exec shell: Replace process image with shell
Uses select() to monitor multiple file descriptors:
- stdin → Read user input → Write to PTY master
- PTY master → Read child output → Write to stdout and file
man 1 script- Script command manualman 2 syscalls- Linux system callsman 3 posix_openpt- PTY creationman 2 select- I/O multiplexingman 3 termios- Terminal attributes