Recurse Center: week 11, day 5

In brief: omg RC is almost over, Vagrant, walking in Chinatown, learning unintended things, manpage sandwiches, and your misandrist terminal

Kind of terrified that there’s officially less than a week left. Came in kind of late today, but then Fridays are optional, and they have a totally different energy. Successfully biked from new-home without getting lost. Different challenges than the old route. The Williamsburg Bridge is WAY more relentless than the Manhattan Bridge — it just goes up, and up, and up, and up — but it doesn’t have the same “bump bump bump” from separate concrete panels that the Manhattan’s got. You win some, and you scratch your head at some!

To my delight, though, both bridges give me a chance to work hard, and then a chance to just fly. They’re a huge part of why I’m even fonder of my bike than I’ve ever been — not necessarily one of the effects I anticipated from biking here.

Back to relational database partytime today. I took a long meandering lunchbreak in the middle (and went to one of the Buddha Bodai places — they are unrelated but have the exact same name, because New York), and I read historical placards, and I witnessed a really sweet art lesson/collaboration/mentoring? in the park, and I found a really awesome no-dumping sign in Chinatown:

And then I came back the extremely long way (“I’ll just stop in here for a minute” is never just a minute), got back into things, and got into trouble!

Okay, not bad trouble. We’re building a tiny fake forum in this class, and I’d spun it up, and apparently didn’t close out of it all the way in the terminal.

I’m using Vagrant with this virtualbox (which, for the record, is a clever way of ensuring your students have a consistent development environment that is likely to work. nice!). And because version control is the coolest, I tried to check git status. Nope; no git in the vagrant box. So I backed out of the vagrant session and tried again. Weird .pyc files and some vagrant configuration stuff, as far as I could tell, but nothing cool and useful that I could see.

I eventually gave up on this, headed back in with vagrant up, and…welp:

Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 8000 is already in use
on the host machine.

To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:

  config.vm.network :forwarded_port, guest: 8000, host: 1234

Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding.

I can translate:

Um, some computers did computer things. Now there is something undead in your computer. It’s your zombie; you deal with it. I have not been trained to handle zombies; I am — hark! — a mere vagrant.

If you want to fix it on your own, you could muck about with something. Godspeed, yo.

Sometimes, I try to fix this. But no. No trying this time. Because it didn’t work.

TO THE GOOGLEMOBILE, THEN

A search for “stop process on port” almost did it; adding “mac” gave me this StackExchange page on the first try.

Things I tried from there:

netstat -anp tcp | grep 8000

I, uh, don’t know what that does (safety alert: don’t run commands you don’t understand, and yes I thought about that when I did this, but it seemed safe enough [famous last words]), but it gave me a line of stuff:

tcp4       0      0  *.8000                 *.*                    LISTEN     

¯\_(ツ)_/¯

Undeterred, I kept looking through the page. (I’ve been amazed at what good information I’ve found in questions closed as “not within the guidelines” on StackExchange.)

Lo, what cleverness is this?

lsof -i:8000

It is a “list [you know, like ls] open files” command and a FLAG and oh yay, look at this output:

COMMAND     PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
VBoxHeadl 31878 liene   34u  IPv4 0xc3c82a3fd2729cff      0t0  TCP *:irdmi (LISTEN)

“But Liene,” you say, “that looks like an opportunity to learn about how to override line width in WordPress!” And you would be right. And it is also not my goal right now, so I’m skipping it. (I love this new version of myself.)

If you wanna see it lined up, though, here’s a visual of the same thing from my terminal:

lsof results

There we go! So clear! Now I’ve got a PID (a process identifier, not the other kind of PID, in case you were wondering). And that’s what I was looking for, so I could use this:

kill -9 <PID>

And voilà. Plugged in 31878 for <PID>, and my vagrant box came right back up (from a full halt, but not needing to download/build anything this time).


I’m thinking it might be cool to learn about what I ran, though.

TO THE PAGES OF MAN (i.e. manpages)

What even is netstat -anp tcp | grep 8000?

So glad you asked.

  • `Netstat` shows network status.
  • -a shows the state of allllll the sockets (even ones used by server processes, which seems particularly relevant here, since it’s a server process getting in Vagrant’s way).
  • -n shows network addresses as numbers, instead of the usual “interpret them and then display them symbolically,” whatever that means.
  • -p shows statistics about the protocol you are toooootally about to give it, except the manpage version sounds like someone is either tipsy or playing Mad Libs, so. (Show statistics about protocol, which is either a well-known name for a protocol or an alias for it.”) I’ll grant that it sounds a little more sensible with the formatting in the page-of-man.
  • That explains what the “tcp” part is for, too! Our friend, the Transmission Control Protocol. I look forward to learning more about tcp stuff later.
  • The pipe (NOW we’re getting to the stuff I already knew!) | just says “okay okay do the thing before this, but then hang on to the result for juuuuuust a second, because I want you to do something else with it.”
  • grep says “I want to find something, but in a difficult command-line way”
  • 8000 plays itself in this saga.

That’s all the pieces of the sandwich. But what does the WHOLE sandwich look like?

  • I want to know some stuff about the network status
  • and I want to know about ALL the sockets and their states
  • and please display network addresses as plain ol’ numbers
  • and I only want to know about tcp stuff; everything else is irrelevant
  • AND once you have THAT…
  • I just want things from the above result that contain “8000,” and I don’t care about anything 8000-free, because that is ALSO irrelevant
  • …okay go!

🍔

YEAH!

Okay and then “lsof” is “list open files” and then there’s the killing command…

“Wait, Liene. What about the flag on lsof?”

…so glad you asked! lsof has a BUNCH of flags. (Check it out, maybe now! Just like, get all “man lsof” with your bad self. Right now! Or maybe later.)

In any case, good ol’ -i is the only one I care about today.

Turns out the info about it is…well, set a -v flag on this one because it is VERBOSE. Ho ho ho, nerd humor!

It, um, “selects  the listing of files any of whose Internet address matches the address specified in i.  If no address is      specified, this option selects the listing of all Internet and x.25 (HP-UX) network files.”

…or as I first read it, “meow meow files meow meow Internet meow meow meow.”

If I’m right, though, that means this command selects the listing of all Internet and whatever-this-other-thing-is network files. So like, just network files.

You can specify any of this stuff, which looks like hieroglyphics but isn’t the worst (also EVERYTHING is optional, which is what the square brackets are for):

                [46][protocol][@hostname|hostaddr][:service|port]

First two square-bracket pairs can be completely ignored. Now we have half as many problemsquestions!

I didn’t specify an address in “lsof -i:8000”, or it would have been in the bracket-pair that starts with @ (where we could have used a name OR a numeric internet address in dot form), but instead there was nothing there. That means we can ditch that bracket-pair, too.

And ooh, there at the end! There’s a colon. We skipped the service part (the manpage example is “e.g. smtp”), because it wasn’t relevant, but OMG the port part is SO RELEVANT.

So — agh this is so good — that means that “lsof -i:8000” means “list all open files that have an internet port of 8000.”

CRAP COMPUTERS ARE AMAZING 💖  💞  💻  😍  💗

And then there’s one more, and the manpage for kill isn’t RAD when it comes to finding out what the -9 is about (I scan for flags! by their names! but it turns out this one is found under “-signal_number”), but it’s not awful. -9 just means “KILL (non-catchable, non-ignorable kill).” I don’t know what “non-catchable” means, but I DO know what “non-ignorable” means, so it’s basically like “okay srs this process has to stop RIGHT NOW right now IMMEDIATELY no takebacks.” -9 means BUSINESS.

Also. If you’re ever like, “ugh, I wish my computer were a misandrist,” and you want to feel like it is, just type “man kill” at the command line and watch how quickly it obeys your command. So anyway your computer is probably a misandrist.

We have friends arriving in town, and I could keep doing this all night, but I need to get home. I barely even got to play with Postgres today! But. I learned a lot more about some cool command-line superpowers. And now man-pages are noticeably less scary.

On another note entirely, to my horror, I sat the whole time I was at RC today, which is usually Not My Thing. And it was awesome instead. Well then. Maybe I’ll work on moving around a bit more this coming week.

Leave a Reply

Your email address will not be published. Required fields are marked *