260 likes | 381 Views
Intro to Unix for Smart People Part II. Joe Morrison, Lab49. Unix graphics architecture. The X Window System Or simply X But not “X Windows”. X Window System Architecture. Cut and paste in X. Open protocol (ICCCM) When user does a CUT
E N D
Intro to Unix for Smart People Part II Joe Morrison, Lab49
Unix graphics architecture • The X Window System • Or simply X • But not “X Windows”
Cut and paste in X • Open protocol (ICCCM) • When user does a CUT • App sends a message to X: My Window now owns selection PRIMARY • When user does a PASTE • App sends a message to X: Please paste selection PRIMARY into my attribute foo • X sends owning app a SelectionRequest event • Owning app sends a ChangeProperty request to X to push data • Owning app sends a SelectNotify request to X to forward to requestor • Requestor can now read the data by sending X a GetProperty request • Benefits • Works cleanly with apps and X server on different network nodes • Allows format negotiation • Works even if apps cannot communicate with each other directly • Allows interesting enhancements (xclipboard app can watch for events and take long-term ownership of selected items)
Display manager – simple scenario • Simple scenario – one computer with graphics capability • Display manager runs first • Starts X server • Runs a graphical “login” program • Graphical equivalent of “getty”
Display manager – simple scenario Pretend this is an X terminal /etc/inittab fork/exec startx xdm fork/exec (respawn) init (pid = 1) wait for X server to start display login / password prompt xlogin exec User-specified X apps to start (xterm, etc.) Start other required processes xdm plays same role as getty (but graphical)
Display manager – complex scenario • More complex scenario – multiple X terminals, one host • X terminal broadcasts “manage me!” • Display manager responds by forking a process to run graphical “login” over the network • Graphical equivalent of telnet daemon • Support hordes of developers with dumb terminals and one giant server
Display manager – complex scenario xdm plays same role as telnetd (but graphical) Broadcast: Can someone manage me? xdm listener for each request, fork/exec xlogin xlogin display login / password prompt exec User-specified X apps to start (xterm, etc.)
Other scenarios • Multiple hosts, each running xdm • Poor man’s load balancing • Large group of X terminals serviced by a small number of hosts • Each X terminal is managed by whichever xdm answers first (usually the least loaded) • INDIRECT mode • X terminals do not broadcast • Instead they contact a primary xdm • Primary xdm delegates to secondary xdm according to desired configuration
Window managers • Ordinary processes running in background • Register with X server to receive notifications when applications start, open windows, etc. • Get to meddle • Relocate new application windows • Draw ornamentation around windows (resize grips, title bar) • Handle visual interaction for resizing, moving, minimizing, maximizing windows, etc. • Send application resize/move instructions • Get to decide • Start menu? Icons? Docks? Button bars? • Can be changed on the fly! • You can write one!
Session managers • Responsible for saving/restoring application state • Standard protocol for communication between window manager and session manager • Enables window manager to offer services like “logout and save session”
Unix desktop = • Display manager + • Window manager + • Session manager
SSH (poor man’s VPN) • Secure replacement for telnet • Also – port forwarding ssh -l 1234:10.0.0.7:80 rasputin.lab49.com 10.0.0.7 Encrypted communication (compressed too!) RASPUTIN ssh client – in addition to telnet session – accepts connections on port 1234 ssh server – in addition to telnet daemon – relays client port 1234 to port 80 on 10.0.0.7 ssh provides a secure, encrypted TCP/IP proxy to any computer reachable from the ssh server
X over SSH • If you can SSH to a Unix machine, you can run any X application on that machine and have it display on yours (regardless of firewalls) ssh -X rasputin.lab49.com Encrypted communication (compressed too!) RASPUTIN ssh client – in addition to telnet session – acts as a proxy X client for all apps started on Rasputin ssh server – in addition to telnet daemon – creates a fake local X server and sets it to be the default; requests are encrypted, compressed, and tunnelled back to the client
Package management with RPM(Redhat Package Manager) • Both a Unix app (manages all installed packages) and a file format • Maintains a database of installed apps • Knows which RPM each file belongs to • Knows what the md5sum of each file should be • To install an application • rpm –ivh myapp-1.3.2.i386.rpm • Checks dependencies, installs all files, runs postinstall scripts, etc. • To remove • rpm –e myapp • The RPM system remembers which files belong to myapp – always removes cleanly • Application does not need to cooperate (badly written app cannot screw up RPM) • Removing an application never results in a different application being uninstallable • To list files in an RPM • rpm –ql myapp • To get general info about an RPM • rpm –qi myapp • To find out which RPM owns a particular file • rpm –qf /usr/bin/emacs • To check whether an application has been damaged • rpm –qV myapp
Package management with APT (Advanced Package Tool) • Rather than operating on individual files, APT is based on repositories so it knows about all packages and their dependencies • Like RPM but more holistic view of your system • If you install an RPM and don’t include all necessary dependencies, it will refuse to install • But if you install using APT, it will quietly install everything needed
Package management with YUM (Yellowdog Updater Modified) • Provides an APT-like experience on top of RPM
About /proc • The /proc pseudo filesystem is a real time, memory resident file system that tracks the processes running on your machine and the state of your system • The contents of the /proc filesystem areused by many utilities which grab the data from the particular /proc directory and display it • You can also write to the /proc filesystem, e.g. writing to the /proc/sys directory enables you to change kernel parameters • echo 1 > /proc/sys/net/ipv4/ip_forward • Examples • cat /proc/vmstat • cat /proc/1234/cmdline • cat /proc/meminfo • The contents of /proc need to be standardized – too many utilities count on the format of /proc files
/proc/vmstat nr_dirty 8 nr_writeback 0 nr_unstable 0 nr_page_table_pages 1040 nr_mapped 53684 nr_slab 11199 pgpgin 1436240 pgpgout 29582742 pswpin 23 pswpout 40 pgalloc_high 2789161 pgalloc_normal 53175006 pgalloc_dma 11 pgfree 56056660 …
The comforts of home • Xscreensaver • XMMS (like Winamp) • Xine / MPlayer (play videos) • GRIP (rip CDs) • Mozilla/Firefox/Opera • Emacs • Eclipse • VNC (remote desktop)
Closing thoughts • In general Unix desktops are primitive compared to other popular operating systems • (NeXT and Mac being notable exceptions) • But it’s not just about features, ease of use, and stability • (This better be good) • It’s also about internal interfaces • Make OS reusable in more contexts • Create a breeding ground for improvements • For example • Accessibility (rewrite the window manager) • Embedded systems (replace /etc/inittab)
Unix versus Windows • Windows: Best platform for creating end-user applications • Unix: Best set of building blocks for general purpose, secure, multi-user, multi-process computing
Final closing thoughts (really) • Windows • Intelligent design • Unix • Mutation and natural selection