![]() |
Baby beginner question about "w" command
My Unix books arrived! :D And I'm beginning my first baby steps into learning Unix. Which means I have a really baby beginner's question. Actually, I have two questions.
Why am I showing up 3 times in Unix? And why does WHAT not show what I'm doing? Code:
[10:48pm] [vicki] [~] You rang? % whoThanks for humoring me with my silly beginner's Unix questions. I gotta start somewhere. :) |
While I'm at it (asking baby Unix questions)... What happens if I enter the exit command? I invisioned all my apps closing down immediately, but then does the terminal stay up? Do I have to reboot? Silly question, I know, but I'd like to know what it would do before I try it.
Never mind this one... I gave it a try. It just closes the window! So much for thinking my who system would shut down. :D But it didn't remove me from the list when I use the w command. I'm still showing up 3 times. |
You show up for each instance of the (umm... well, I guess it would be the...) shell (or something like that). So, "console" is from when you logged in, ttyp1 is when you opened Terminal.app, and ttyp2 is from when you opened a new terminal window.
I don't know what WHAT is. The application console that displays logs is different from the above console, as you seem to have discerned. Perhaps the latter is the equivalent of what you get when you log in as >console. Sort of. If you issue the exit command, we all die. Actually, it just terminates the process of your terminal window (or something). So it is like closing the window, except the window is not closed. You know what I mean. [Oh. You already figured that out.] Maybe someone else knows what I mean. |
I think, in fact, most of what I said above is off. As you point out, there is not one less of you, if, with multiple terminal windows open, you issue an exit command, or, for that matter, close a window. One does definitely multiply oneself by opening new windows, though.
|
the issue with w and who is that there is a bug. exiting a shell doesn't decrement the login file utmp or wtmp, i forget. it's a bug. shoud be corrected in jag, but don't rely on current incarnations of w and who.
as for what, what what does your book refer too? always refer to local % man command as for what is what |
Vicki,
What books did you get? I'm about to get some unix/os x books myself and since you seem to do things quite thoroughly and thoughtfully, maybe I'll forgo the whole amazon.com research thing and just get what you got. Yeah, I'm lazy. I read in TidBits that Mac OS X Unleashed was worth a read and covered the terminal, etc. That was my research. Hombre, "If you issue the exit command, we all die." Boy, that unix is some powerfull stuff. takayuki |
MacOSX Unleashed.......
.....is a very good book for neophytes, like ourselves. It has a great reference section for the Unix commands, and goes through alot of useful tips and tricks with a firm basis. It does hold your hand at litle then lets you go your own way.
|
Quote:
Merv - So it's a bug. I was thinking maybe I was there twice, one for user and one for admin? I'm still not sure what console is all about. Maybe it will gel in my brain as I learn more? Takayuki - I was lazy too! :D I took the recommendations that were in the OSXGuide. The book I'm going through first is Sams Teach Yourself Unix in 24 hours (Sams Publishing). I also bought Unix in a Nutshell (O'Reilly & Associates). I haven't gone through the books far enough to make any real evaluation on them, but I have always found the books by O'Reily to be very good. I bought Unix in a Nutshell as a reference book. Sams Teach Yourself Unix in 24 Hours seems - so far - to be exactly what I need as a baby beginner. It completely holds your hand. But what I like even better is that it is helping me to understand better what I'm doing. Anyone can throw a command at you, and you can type it into the terminal to see it work. But for me to truly learn it, I need to understand why I'm using a particular command, what my goal is, and why that command will accomplish that goal. So far, Sams Teach Yourself in 24 Hours appears to give me that necessary understanding. I'll be able to offer a better opinion on it as I read more of it. Regarding WHAT is WHAT... I apologize for not being more clear. When I enter the w command, it's supposed to tell me a number of things, including WHAT each person is doing. The book says it's supposed to be showing that I'm doing the w command. But it's not. It's just showing a - (dash) under each of my 3 listings. So I was wondering why it's not telling me what I'm doing as it was supposed to do. Maybe another bug? Quote:
Quote:
|
w is broken in OSX
The 'w' command is supposed to show you what what each user is doing on the machine, such as this output from my Sun workstation:
$ w 7:04am up 113 day(s), 20:45, 2 users, load average: 0.45, 0.43, 0.43 User tty login@ idle JCPU PCPU what john pts/5 7:03am 1 find / -name core -ls john pts/7 7:04am w $ I am logged into two sessions, and each has it's own shell (in the case of Sun, a Bourne shell (/bin/sh), in the case of MacOSX a tcsh shell. I am running the 'find' command in one shell, and the 'w' command in the other shell. In order to see what programs you ARE running in MacOSX, you can use the 'ps' (process list) command: ps -ao user,command USER COMMAND john -tcsh (tcsh) root ps -ao user command We see User 'john' running a shell, and user 'root' running the command that generated the above output. There are many other options to the ps command - I suggest you try reading the man pages for ps (man ps) and play with it a bit. Each instance of a 'terminal' window in MacOSX spawns a 'shell' for you to work in. The shell is associated with the Terminal program, thus when you quit the terminal (or close the terminal window), the shell is killed as well. The 'console' is a special form of terminal. 'Console' in unixland is a device that programmers use to dump output from programs. Usually, output is directed to a log file, or the syslog daemon, but it can be directed to both a log file AND the console device. It's a quick way to see various status messages from programs running on your machine. The Console app has options to view other log files as well. When you enter the 'exit' command you are telling the current instance of the terminal app to terminate. Any programs started under that instance of terminal app will also terminate. An 'instance' in this case does not refer to the terminal app itself, just the WINDOW in which you entered the command. If you have 10 windows open at once, and type 'exit' in one window, just that window will close - the other 9 will remain open. |
Quote:
Quote:
For example, I did a restart and immediately opened the terminal. Issuing a w command showed 2 lines - 1 console and 1 user (me, vicki). Cool. So I got rid of that second user line that I had before. So I opened a 2nd Terminal window. As expected, it created another user entry showing me (vicki) twice. However, issuing the exit command in that second window did not remove the second listing when I reissued the w command. In fact, after opening 5 new terminal windows -- and closing each by issuing the exit command -- I am now listed 6 times (one for each of 5 shells, 4 of which are closed now, and 1 for the console). The only way I have found so far to remove myself from those 6 listings is to do a restart of my Mac. Is this how it is supposed to work or is this merely a result of w being broken in OS X? Not that any of this is truly important to me (right now), but I would like to understand what's happening. If it's due to a bug, then so be it. But if it's due to something I'm doing, then I'd like to correct my mistake. So my question is... If I open 5 shell windows in Terminal, how do I remove myself from being listed 6 times when I issue the w command (other than doing a restart)? Is it possible? Or is this just part of the "w is broken in OS X" bug? |
i thought we covered this...
"the issue with w and who is that there is a bug. exiting a shell doesn't decrement the login file /var/log/utmp or /var/log/wtmp, i forget. it's a bug. should be corrected in jag, but don't rely on current incarnations of w and who." Quote:
as for the exit command, it merely quits the current shell level, returning to its caller. e.g., my prompt contains the value of the environment variable SHLVL>1, which is incremented for subshells and script invocations... Code:
$ bash # start a bash subshell |
Quote:
Quote:
Quote:
|
When you start up a Terminal window, what you are really doing is running a program, in this case tcsh. Now in that same window, if you type 'tcsh' again, you start a new process. But if you haven't changed your prompt, it looks exactly the same as it did before.
The way to tell the difference is with ps. If I enter tcsh, my ps looks like: Code:
1459 std Ss 0:00.14 -tcsh (tcsh)Code:
1459 std Ss 0:00.14 -tcsh (tcsh)Does that make a little more sense? Also, part of the confusion when you ask about WHAT is that 'what' is a Unix command by itself... :) |
thanks, nkuvu.
Quote:
get used to perusing the man pages and searching for keywords with the /pattern search operator, e.g., Code:
% man tcshsee environment variable SHLVL Code:
% man tcshjust to throw a wrench into this, set your pager to less (instead of more) to get a richer man page environment. put the following commands in your tcsh shell startup ~./login ... setenv PAGER less setenv LESS -FiMs~ as an exercise, find what less options FiMs~ means in the man pages for less i promise, vicki, it will get easier and there will be a light at the end of the tunnel (that isn't an oncoming train if you exercise caution). |
Thank you! Yes, I understood the "stacked plate" concept as presented. In my mind, I relate this to routines and subroutines, including the passed exit values.
I did not understand how/where I am to enter /exit or /shlvl. However, I gather you're wanting me to do a page search on these "words" on the man pages for tsch. If so, I'm just using the Find Panel under the Edit menu. I also have ManOpen, and can use the GUI Find to search through a displayed man page, as well. Attempts to enter /exit or /shlvl in the terminal prompt failed (and methinks if you intended for me to enter those as commands, you would have prefaced them with % so I don't believe that's what you had in mind). Whatever the method, I did search, find and read about exit in tsch. And it made sense. At least I think it did. In my own words, opening a new window in the terminal is simply starting a new process. What I may be wrong about, and need clarification, is a subprocess versus an unrelated process (sorry, I don't know the proper words to use here). If I issue a command in a tcsh which invokes a subprocess, the the subprocess is a "related" process (another plate stacked on top). When that subprocess exits (successfully/unsuccessfully), it returns an exit value back to the process that originally invoked it. However, if I open two windows in the terminal, each are independant of each other (two separate stacks of plates). If one exits, it does not return any value to the other because they have no relation to each other. Is that correct? Did I make any sense in how I've said that? Is there anything simple I can do at the terminal that will cause a second terminal window to open (a "related" process) -- and then run something in that second terminal window that will force it to exit (and close the window) which I can then test for the exit value in the first window/process? Again, I'm not sure if I'm making any sense here without knowing the proper terminology. Quote:
I could not find any reference to FiMs~, even when looking at the man pages for less. I tried % apropos FiMs in the termanal and using ManOpen, but still came up empty handed. Quote:
|
load up the plate!
1. the pager program (more or less) is interactive. the "prompt" at the bottom reads commands. one command is 'h' for help. hit h and in more, you'll see a half screen of commands and one is /<regular expression - search... in less, you'll see a full screen of commands and under searching you'll see /pattern meaning... enter the / char and the prompt starts to read your input, enter what to search for... Code:
% man tcsh2. regarding processes vs. subprocesses, you are correct. two terminal app windows are unrelated, except that they are owned by you and are subprocesses (children) of the terminal app process. in the ps long listing, PPID means parent process ID and if you follow the chain of command, all PIDs lead to parent PID 1, the init process... Code:
$ ps al | colrm 30 60Quote:
4. if you don't have ~/.login, just create it. as you get further into the shell, you'll be wanting to set up your shell startup environment by populating the shell startup scripts with your commands. ~/.login is one of those shell startup scripts. see man <your shell> and search for "startup" 5. less options. invoke man less and in the Options section, you'll see that it explains how you can set the env variable LESS to the less startup options. the options of FiMs~ are enumerated here (there) ; each char of FiMs~ is a seperate -switch so you won't find the string "FiMs~" but you will find the separate switches -F -i -M -s -~ |
Uncle (I cry). I'm lost. I'm getting about 1/2 of what you're saying, but I'm stuck on the ./login file, and I can't go any further until I create it.
I tried to create it using BBEdit. It won't allow me to use the "/" character in the filename. Fine. So I used pico. It seemed happy with naming the file ./login, but when I try ls -a, no such file/dir is listed. I'm in my ~ dir (/Users/vicki/). That's where I thought I was saving the file. Please throw me a clue. I can't proceed until I create the ./login file you recommended. |
regrets.
./login is a typo the file name is .login it resides in ~/ it's full reference is ~/.login - not ./login in a short time, you'll be able to spot and correct these little foibles. Code:
$ ll ~/.loginCode:
% cd # cd to home./login refers to the filename login Code:
$ touch ./login |
Ah! (light just switched on). So what I did was create .login in my / dir. Got it. Moved it. Now I can start chewing on the rest of your info.
And if you want a laugh... it took me about 30 minutes before I figured out what the "pager program" was. :D Baby steps, indeed. :) |
yeah, this is the point where a lot of people give up and go shoot skeet.
your tenacity will pay off; there'll soon be enough lights going off to be seen from space. at an old job, the pager program was the annoying collection of code that dialed my beeper every time so much as a gnat farted near the machine room. so, it is with some disgust and revilement that i refer to the "file perusal filter for crt viewing" as a pager, but it is the argot of the day, and we must attempt to approach convention. |
Hint on the FiMs~
This is a collection of options, not a single option. So I sincerely doubt you'd be able to find anything by looking for the full word. :) |
Farting gnat! LOL! :D
No skeet shooting over here. I may feel like shooting the terminal, shooting my books and shooting my kids if they won't stop fighting while I'm trying to digest all of this (just kidding on the kids, of course), but no skeet shooting. Believe it or not, I'm actually enjoying this no matter how much hair I might end up with in the end. :) 1. I'm getting "pattern not found" with /shlvl. But if I do a "Find" in the terminal, it's there. And if I do a "Find" while in ManOpen, it's there too. My logic is now on tilt. :confused: 2. I follow the logic (so I think). I follow the numbers. I have no clue what you've displayed there. I've seen that info before (or something similar), but am not comprehending it. But it's the example that's important, not the details of the example, right? 3. Okee-dokee. There's always another day. 4. Done. :) 5. Gotta problem. In the current shell I'm in (ttyp1), % man tcsh spits out lots of cool info. But I opened a new shell (new window - ttyp2), and suddenly % man tcsh isn't too happy (methinks the setenv commands are in affect in the new shell): Code:
[1:16pm] [vicki] [~] Exit, and we all die: % man tcshHowever, I do still have ttyp1 open. FiMs~ means (-i) ignore case (-M) long prompt (more verbose) (-s) squeeze blank lines and (~) make lines at EOF blank. I ran across "F" without a dash (scroll forward), making me think that's what was intended, but I don't know why I'm having problems with -FiMs~. I tried F -iMs~, but, of course, that produces an error. |
regrets. my less is fink's less which is more than OSX's less.
re: 1 & 5. with fink's less (same author, newer version) the -F switch... Quote:
Code:
$ which less/SHLVL would find it, right? so, remove the F from the LESS varliable and restart your shells (to re-initialize your shell environment). grokking now? re: 2. consult % man ps get familiar with ps output - ps wwaxl - all processes have a process ID (PID) and a parent PID (PPID) my example merely climbed up the parent tree from a bash shell process, whose parent is terminal whose parent is windowserver whose parent is init whose parent is kernel. re: fink vs. vanilla OSX, i will try to remain OSX vanilla with commands so as not to stuff up these issues. |
It must have been all of those farting gnats that made ya do it. :p
And good news. By golly, I think I understood all of your last message! :D While I had the F flag in my env for less, neither /shlvl or /SHLVL would work. I errored out before I even got the chance to try. Now that I have it corrected, both work as advertised. :) I've just gone back to read this thread again, and I'm beginning to grok it. :D In the processes you were showing me, the relationships are kernal to WindowServer to Terminal to whatever bash is (a process you're running). Yeah, I know you spelled it out for me. I wanted to spell it myself. ;) So if I want to see what's called what, I start by looking up the PPID for the process to see who's its parent. I can look up that PPID to find its parent. And so on and so forth until I finally reach the kernal. AND this means I can look to see if a process I'm running has called another process (related) or is just another process running along side of it (unrelated). Right? BTW, nkuvu, I'm not ignoring you. I appreciate your help and have been reading and learning from your help as well. Thanks. :) |
| All times are GMT -5. The time now is 10:31 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.