![]() If you picked the right session, you should find your command still running (if it hasn't finished in the meantime) so that you can continue your work. Once your connection is back up, log in to your system with SSH again and runįrom the results pick one session (e.g. step 1 : top -u username step 2 : Press k to kill process accordingly. Now let's assume you had a long running command or process in a screen session, something which normally takes a long time, and suddenly your connection drops. User names come from a database, but user IDs are whatever a process running setuid () chooses. Man screen My Connection Dropped - What Can I Do? It would also be useful for me to be able to log the processes still active during as much of the shutdown process as possible. Unlike the who command, the w command gives you more information about the running processes for each user. The next command you can use to show the status of various SSH sessions and users connected to the server is the w command. ![]() If you want to learn more about screen, run: Also read: How to Create an SSH Honeypot to Catch Hackers in Your Linux Server. You will then fall back to another screen session (if you use more than one) or to the normal SSH terminal, if no more screen sessions are open. To leave and finish a screen session, finish all current tasks in it (top can be finished by typing q, etc) and then type: ![]() Where 1 is the name of one of the sessions from the screen -ls output. To reconnect to one of these sessions, run: To get a list of your current screen sessions: On your original / normal SSH terminal, run: ![]() To detach a screen session and return to your normal SSH terminal, type: You can browse your two screen sessions by running: Now let's create another screen session by typingĪ new, blank screen session opens, and there we run Now let's play around with screen a little bit. To close a screen session where all tasks are finished you can type Ctrl+a d - Detaches a screen session (without killing the processes in it - they continue).Ctrl+a p - Switches to the previous screen session (if you use more than one).Ctrl+a n - Switches to the next screen session (if you use more than one).Ctrl+a c - Creates a new screen session so that you can use more than one screen session at once.These important commands begin with CTRL+a to distinguish them from normal shell commands: Press Space or Return to get to the command prompt: This creates a screen session or window (although you don't see it as such) in your current SSH terminal: Run ps $$ to take a look at how your active shell appears on the list and build a regular expression from the second column.With screen you can create one or more sessions in your current SSH terminal which allows you to leave them (and the commands running) in the background should you disconnect from your session. If you're running something else, your terminal emulators may be named differently. I suspect what you want is: ps x |awk 'NR = 1 || $2 ~ /pts/ These conditional statements are logical, so you can combine || with & and parentheses, e.g. Using regular expressions, you can combine the first two bullets as ps x |awk '$3 ~ //'. You can add the title with 'NR = 1 || … (number of records = 1, aka line 1) in the AWK command. These are conditions and we're simply using AWK's default action (print matches, which could also be written like to print the whole line). Here we're just calling out fields by number and looking at their values ( $) with regular expression matchers ( ~). Running in the foreground: ps x |awk '$3 ~ /\+/'ĪWK is really powerful.Stopped by job control ( Ctrl+ z without bg): ps x |awk '$3 ~ /T/'.Connected to any terminal: ps x |awk '$2 ~ /pts/'.It's unclear (to me) what you'd want this global jobs call to do beyond just listing all processes owned by the current user ( ps x), but you could filter that listing by terminal and/or by state.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |