date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,410,012,509,000
My scenario Relevant entries in my /etc/hosts (I have them written in the same order you see them here) 172.22.5.107 www.wordpress-rend-adri.com 192.168.1.116 www.wordpress-rend-adri.com I use my laptop in my house and school, hence I'm always dealing with 2 address spaces: 192.168.1.0/24 172.22.0.0/16 So I have those entries because I have a vm with a Wordpress for doing an exercise. That way, it doesn't matter where I am that I'll be able to access my Wordpress (as long as the DHCP offers me the same IP in both networks obviously) My question Knowing all of this, now I can tell you that I just made that configuration in my /etc/hosts because one teacher said to me that I only can have 1 record for a name pointing to a single IP. He said to me that If I had a doubled register for the same name, It always take the first one, and stops. But he also said to me that I should try it out, so I did. The reality, is that for example in my house (where I'm using 192.168.1.0/24), even though the first record is for the other IP, I still can make a connection, and when I ping the name, the correct IP answers to me. And yes, I did try to be completely sure about this, and I did it in an incognito firefox window, and I also tried to comment the line of the IP of my house to check what happened. Then, I tried to exchange both records. I mean, I just did this: 192.168.1.116 www.wordpress-rend-adri.com 172.22.5.107 www.wordpress-rend-adri.com So in this case, obviously it is still working. And when I went to school, the same happened when using the other address space. So... ¿Why is it said that you can only have 1 record for a name in your /etc/hosts, if this configuration actually worked for me? ¿Is firefox, the ping binary, or anything that you use, doing an internal process of name resolution to check what's the entry that actually works, before doing the final connection? I'm asking this because for example with ping, you just start getting an answer from the IP that works. You don't get failed connections like trying to connect to the other previous IPs
I have done a few tests on my debian/wsl ~$ uname -a Linux DESKTOP-OMM8LBC 4.4.0-17763-Microsoft #864-Microsoft Thu Nov 07 15:22:00 PST 2019 x86_64 GNU/Linux # /etc/hosts 172.22.5.107 www.wordpress-rend-adri.com # Unreachable IP from my LAN 216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com 192.168.0.12 www.wordpress-rend-adri.com # IP for another running machine on my LAN 157.240.1.35 www.wordpress-rend-adri.com # IP for www.facebook.com ~$ ping www.wordpress-rend-adri.com PING www.wordpress-rend-adri.com (192.168.0.12) 56(84) bytes of data. 64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=1 ttl=64 time=49.9 ms 64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=2 ttl=64 time=5.85 ms 64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=3 ttl=64 time=5.58 ms 64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=4 ttl=64 time=6.25 ms 64 bytes from www.wordpress-rend-adri.com (192.168.0.12): icmp_seq=5 ttl=64 time=6.19 ms --- www.wordpress-rend-adri.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 9ms rtt min/avg/max/mdev = 5.575/14.754/49.919/17.584 ms So ping picked the local IP placed between two working WAN IP. Second test: /etc/hosts 172.22.5.107 www.wordpress-rend-adri.com # Unreachable IP from my LAN 216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com #192.168.0.12 www.wordpress-rend-adri.com # IP for one running machine on my LAN 157.240.1.35 www.wordpress-rend-adri.com # IP for www.facebook.com ~$ ping www.wordpress-rend-adri.com PING www.wordpress-rend-adri.com (172.22.5.107) 56(84) bytes of data. # Stuck here Third test: /etc/hosts #172.22.5.107 www.wordpress-rend-adri.com # Unreachable IP from my LAN 216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com #192.168.0.12 www.wordpress-rend-adri.com # IP for one running machine on my LAN 157.240.1.35 www.wordpress-rend-adri.com # IP for www.facebook.com ~$ ping www.wordpress-rend-adri.com PING www.wordpress-rend-adri.com (216.58.198.164) 56(84) bytes of data. 64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=1 ttl=54 time=24.5 ms 64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=2 ttl=54 time=22.4 ms 64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=3 ttl=54 time=21.7 ms 64 bytes from www.wordpress-rend-adri.com (216.58.198.164): icmp_seq=4 ttl=54 time=30.5 ms --- www.wordpress-rend-adri.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 7ms rtt min/avg/max/mdev = 21.734/24.768/30.457/3.440 ms Fourth test: /etc/hosts #172.22.5.107 www.wordpress-rend-adri.com # Unreachable IP from my LAN 216.58.198.164 www.wordpress-rend-adri.com # IP for www.google.com 192.168.0.12 www.wordpress-rend-adri.com # IP for one running machine on my LAN 192.168.0.1 www.wordpress-rend-adri.com # IP for my router 157.240.1.35 www.wordpress-rend-adri.com # IP for www.facebook.com ~$ ping www.wordpress-rend-adri.com PING www.wordpress-rend-adri.com (192.168.0.1) 56(84) bytes of data. 64 bytes from www.wordpress-rend-adri.com (192.168.0.1): icmp_seq=1 ttl=64 time=1.56 ms 64 bytes from www.wordpress-rend-adri.com (192.168.0.1): icmp_seq=2 ttl=64 time=1.35 ms --- www.wordpress-rend-adri.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 2ms rtt min/avg/max/mdev = 1.349/1.455/1.561/0.106 ms So my conclusion is that ping does not try one IP after another. It favours router, local IP over WAN IP. Update : The choice of IP above is confirmed by following python command: python -c 'import socket;print(socket.gethostbyname("www.wordpress-rend-adri.com"))'
Different IP:hostName mappings for same host in `/etc/hosts`. Why does this work?
1,410,012,509,000
I have two host file list like this: file1.hosts 0.0.0.0 site1.com 0.0.0.0 site2.com file2.hosts 0.0.0.0 site1.com 0.0.0.0 site3.com Now I want one list that looks like this: hosts.hosts 0.0.0.0 site1.com 0.0.0.0 site2.com 0.0.0.0 site3.com What is the best way to get this? I tried it with join but I don't get it to work.
You could use sort instead. The -u-Option supressed duplicates in the output: $ sort -u file*.hosts | tee hosts.hosts 0.0.0.0 site1.com 0.0.0.0 site2.com 0.0.0.0 site3.com Note that I'm using tee so that we get to see the output while creating the file. You could just as well just use redirection instead: $ sort -u file*.hosts > hosts.hosts
Pair two file / Remove duplicate entries
1,410,012,509,000
I have a Linux server # uname -a Linux site 3.12.39-47-default #1 SMP Thu Mar 26 13:21:16 UTC 2015 (a901594) x86_64 x86_64 x86_64 GNU/Linux # lsb_release -a LSB Version: n/a Distributor ID: SUSE LINUX Description: SUSE Linux Enterprise Server 12 Release: 12 Codename: 12 I had to change network settings. I've set one interface as DHCP in Gnome GUI. Since that moment I have a new problem: my server forgets its own host name every day. Its host name is "site", but when I check #hostname host Then I set #hostname site Then check #hostname site However, about in day later I check again #hostname host Why does it happen? /etc/hostname file contains: site /etc/hosts file contains: 127.0.0.1 localhost 127.0.1.1 site
Your DHCP client can be configured to override the hostname given to the machine by the DHCP server. Depending on what DHCP client you use, this may be done differently. dhclient may be configured with supersede host-name "site"; in /etc/dhclient.conf, for example. Unless you have very special requirements, I'd suggest you make the entry in /etc/hosts as 127.0.0.1 localhost site This says "localhost has IP address 127.0.0.1 and site is an alias for it".
My Linux server forgets its host name every day
1,410,012,509,000
What are the rules that decide what goes into the initial /etc/hosts file of a a server with these characteristics? It has a internal IP address for the internal subnet. which is in the 172.20.x.x range It has a public facing IP address which has a 1 to 1 mapping with the internal IP address ifconfig only shows the internal IP address, which is 172.20.x.x,which doesn't seem to be part of the range reserved for internal networks (which is what has me somewhat confused)
first rule syntactically correct second rule logically true third rule depends on your distro. I'd expect an entry for localhost and possibly for the system's hostname. localhost may be an ipv6 entry (::1) in which case there may be an additional entry for ipv4-localhost What you should you put in the hosts file is any IP address to domain name relations that you do not want to rely on DNS to determine. This is not default, this is customisation.
What are the rules that determine the default contents of an /etc/hosts file?
1,410,012,509,000
Possible Duplicate: How can I make iconv replace the input file with the converted output? I'm writing a script to change the content of my hosts file but I got stuck on the head output redirection. If I do head -n -1 hosts >hosts my hosts file will result empty and yes, it has more than 1 line.
That's because your shell truncates the file when you redirect to it. This happens before head gets a chance to read it. You can either use a temporary file: head -n1 hosts > hosts.tmp && mv hosts.tmp hosts Or use sponge from the moreutils packate: head -n1 hosts | sponge hosts
Redirecting head output for update hosts file [duplicate]
1,410,012,509,000
What is the correlation between these programs? tcpd and inted/rinetd are very old but despite this they are still present in many distributions ... why? And there is also a correlation between hosts.allow and hosts.deny with tcpd but i noticed that these files are present even when tcpd is not installed ... (trying with the command dpkg also noticed that hosts.allow/deny is not correspond to no package) ... well .. a mess. Who helps me clarify? Thanks
The traditional setup is to use inetd to open listening sockets, similar to what systemd is doing with socket activation now, only thirty years before that. inetd will unconditionally start the daemon when a connection comes in. For some rudimentary access control, you'd configure inetd to start tcpd instead of the real server. This program would check that the connection is allowed according to the hosts.allow and hosts.deny files, and then execute the real service if it is. This is significantly older than iptables or similar host-based firewall solutions, so it will also work on stacks that do not have a firewall at all, like AmiTCP or Miami on AmigaOS. The other upside is that the configuration to check the source address is part of service startup, so once it is configured, there is no way to accidentally expose services by flushing the firewall rules. The downside is that the port is initially open, so a network scan will show it, and the connection is immediately closed after it has been established. The hosts.allow and hosts.deny files are no longer shipped, as "missing" files mean "allow all connections", so these form a valid configuration on their own, and anyone still using them probably knows what they are doing. Note that when you use tcpd for access control, you lose the benefit of the wait option in inetd, where the service is started with the listener socket and is responsible for accepting further connections after being started (i.e. where you only have a single instance for multiple parallel connections). There is no udpd, because verifying the source of UDP packets is impossible.
tcpd, inetd/rinetd and iptables
1,410,012,509,000
I noticed that when I create a tunnel locally from my PC to the remote one, for some devices (generally routers), the connection via http or https does not take place. I get a pop-up that says: The 'Host' field contained in Http header is invalid If setting the following in the file hosts file: 127.0.0.1 modemtim and I connect using modemtim and not only 127.0.0.1, everything works correctly. SSH command: ssh -L 8080:<IP_REMOTE_ROUTER>:80 <USER>@<REMOTE_TUNNEL> Why?
A typical http request looks like this if you connect to http://google.com/?q=icarus GET /?q=icarus HTTP/1.1 Host: google.com User-Agent: mozilla/123 Accept: */* Low cost web service providers host many many domains such as www.yourdomain.name and www.mydomain.us on a single machine. The web server on that machine looks at the Host: header to see which set of files to use. If you connect to http://127.0.0.1/index.html and this is forwarded to www.yourdomain.name the remote webserver will have a Host: 127.0.0.1 header which doesn't help it decide which set of files is wanted. Adding an entry to /etc/hosts and making the request to http://www.yourdomain.name/index.html fixes this issue.
Clarifications for SSH tunnels over HTTP (or HTTPS)
1,410,012,509,000
I'm trying to write a script that will check what is the last modified/created file on the server, then copy it to my homedirectory on this server and then copy this file from node to my local machine. I would like to point out, that I am learning how to do this, so I don't have skill at all. Here is my script, don't look at "fr" option as it's for testing things localy. #!/bin/bash set -xv dcma=some_server_name1 dcfr=some_server_name2 echo "FR czy MA?" read dc if [ "${dc,,}" == "fr" ] then echo "Wybrales Frankfurt!" cd test/ ; out=$( ls -1tr | tail -n 1 ) ; cp $out ../ elif [ "${dc,,}" == "ma" ] then echo "Wybrales Boston!" cmd=$( ssh -t $dcma ' cd /opt/automation/repository/hosts/ ; out=$( ls -1tr | tail -n 1 ) ; sudo cp $out ~/ ; ls -1tr ~/ | tail -n 1 ' ) cmdv=$( echo "$cmd" ) echo "Ostatnie wybrane hosty na serwerze: $cmdv" scp -r some_server_name1:~/"$cmdv" . fi Script is failing on SCP command, as it's says that there is no such file or directory mentioned by $cmdv variable. Here is output with set -xv. user-VirtualBox:~/hosty-skrypt$ ./hosty-v8 dcma=some_server_name1 + dcma=some_server_name1 dcfr=some_server_name2 + dcfr=some_server_name2 echo "FR czy MA?" + echo 'FR czy MA?' FR czy MA? read dc + read dc ma if [ "${dc,,}" == "fr" ] then echo "Wybrales Frankfurt!" cd test/ ; out=$( ls -1tr | tail -n 1 ) ; cp $out ../ elif [ "${dc,,}" == "ma" ] then echo "Wybrales Boston!" cmd=$( ssh -t $dcma ' cd /opt/automation/repository/hosts/ ; out=$( ls -1tr | tail -n 1 ) ; sudo cp $out ~/ ; ls -1tr ~/ | tail -n 1 ' ) cmdv=$( echo "$cmd" ) echo "Ostatnie wybrane hosty na serwerze: $cmdv" scp -r some_server_name1:~/"$cmdv" . fi + '[' ma == fr ']' + '[' ma == ma ']' + echo 'Wybrales Boston!' Wybrales Boston! ssh -t $dcma ' cd /opt/automation/repository/hosts/ ; out=$( ls -1tr | tail -n 1 ) ; sudo cp $out ~/ ; ls -1tr ~/ | tail -n 1 ' ++ ssh -t some_server_name1 ' cd /opt/automation/repository/hosts/ ; out=$( ls -1tr | tail -n 1 ) ; sudo cp $out ~/ ; ls -1tr ~/ | tail -n 1 ' some_username@some_server_name1's password: Connection to some_server_name1 closed. + cmd=$'hosts.merged.1558094140821\r' echo "$cmd" ++ echo $'hosts.merged.1558094140821\r' + cmdv=$'hosts.merged.1558094140821\r' ' echo 'Ostatnie wybrane hosty na serwerze: hosts.merged.1558094140821 Ostatnie wybrane hosty na serwerze: hosts.merged.1558094140821 ' .cp -r 'some_server_name1:~/hosts.merged.1558094140821 some_username@some_server_name1's password: : No such file or directoryhosts.merged.1558094140821 Any idea how to solve this? Also I can't place this script on target machines as it's against company policy.
I have found a solution. Turns out, that variable had an attached "\r" at the end. I solved this by using tr command. cmd=$( ssh -t some_server_name1 ' cd /opt/automation/repository/hosts/ ; out=$( ls -1tr | tail -n 1 ) ; sudo cp $out ~/ ; ls -1tr ~/ | tail -n 1 ' ) cmdv=$( echo "$cmd" | tr -d '\r' )
Variable for SCP command in script
1,410,012,509,000
I added some custom (non-TLD) aliases to my /etc/hosts to get rid of IP addresses in my services configuration files. Are there any caveats/gotchas/security implications i should be aware of?
Generally, adding convenience entries to /etc/hosts won't cause any problems per se, but you may find yourself momentarily stymied when you move to another host (e. g. via ssh) and your shortcuts do not work. It's possible some oddball applications will eschew the system call for DNS resolution and do it "by hand" so to speak, and if poorly written or designed might skip checking /etc/hosts, but I suspect these are few and far between.
Is it okay to add something non-TLD non-hostname as a host alias?
1,410,012,509,000
Have multiple vm machines that am using for studying, and have come up with this script for copying some files from vm's to my local machine: SG=rohos; date; for i in `cat /etc/hosts | grep "$SG-" | awk '{print $2}'` ;do echo "Logging into ${i}";ssh -i /root/.ssh/vm_private_key keyless-user@${i} "sudo mkdir -p /tmp/${SG}/${i}; sudo cp /var/some.log /tmp/${SG}/${i}/ ";done What could be changed in this script so that multiple typing of destination directories for mkdir and cp could be avoided? Or if you have a better tool like rsync or something else please enlighten me. SG=rohos date for i in `cat /etc/hosts | grep "$SG-" | awk '{print $2}'` do echo "Logging into ${i}" ssh -i /root/.ssh/vm_private_key keyless-user@${i} "sudo mkdir -p /tmp/${SG}/${i}; sudo cp /var/some.log /tmp/${SG}/${i}/ " done
Your script can't do what you want. As written, it will only ever copy files on remote hosts to /tmp/$SG/$i on the same remote host. You need to use scp instead of ssh and cp. For example: SG=rohos date for i in $(awk "/$SG-/ {print \$2}" /etc/hosts); do echo "Logging into $i" mkdir -p "/tmp/$SG/$i" scp -i /root/.ssh/vm_private_key "keyless-user@$i:/var/some.log" "/tmp/${SG}/${i}/" done If you want to preserve the timestamps and permissions of the copied files, add -p to the scp command's options. or add -r for a recursive copy of entire directory trees. See man scp for details of scp and its options.
copy files from multiple remote machines to local and create directories for remote machines
1,301,568,488,000
I was analyzing some web heads looking at htop and noticed the following Uptime: 301 days(!), 23:47:39 What does the (!) mean?
From htop source code, file UptimeMeter.c, you can see: char daysbuf[15]; if (days > 100) { sprintf(daysbuf, "%d days(!), ", days); } else if (days > 1) { sprintf(daysbuf, "%d days, ", days); } else if (days == 1) { sprintf(daysbuf, "1 day, "); } else { daysbuf[0] = '\0'; } I think ! here is just a mark that server has been up for more than 100 days. Reference http://sourceforge.net/p/htop/mailman/htop-general/?viewmonth=200707
What does the (!) mean after uptime on htop
1,301,568,488,000
How do I install htop for macOS (OS X)? (The easiest and laziest path)
Here is the laziest way (or homebrew way) First install Homebrew if you haven't Second brew install htop Third, done
How do I install htop in mac OS X?
1,301,568,488,000
Occasionally, I need to check resources on several machines throughout our data centres for consolidation recommendations. I prefer htop primarily because of the interactive feel and the display. Is there a way to customise some settings to my setup for htop? For example, one thing I'd always like to have shown is the average CPU load. Important note: Setting this on specific boxes isn't feasible - I'm looking for a way to set this dynamically every time I SSH into the box. Is this possible at all?
htop has a setup screen, accessed via F2, that allows you to customize the top part of the display, including adding or removing a "Load average" field and setting it's style (text, bar, etc.). These seem to be auto saved in $HOME/.config/htop/htoprc, which warns: # Beware! This file is rewritten by htop when settings are changed in the interface. # The parser is also very primitive, and not human-friendly. I.e., edit that at your own risk. However, you should be able to transfer it from one system to another (version differences might occasionally cause a bit of an issue). You could also set up a configuration, quit, and then copy the file, so that you could maintain a set of different configurations by swapping/symlinking whichever one with htoprc.
How can I set customise settings for htop?
1,301,568,488,000
It there a way to display the complete command line in htop (e.g. in multiple lines or with a moving banner). With the default setting where only one line is displayed it isn't possible to distungish all processes, e.g. different java programs (because class or jar argument follows a bunch of arguments) or programs with long absolute path of binaries. Omitting the full absolute path in favour of only the binary would be a compromise where distinction would not be optimal, but better in some cases. I checked out the settings and the manpage and didn't find an option suitable in my understanding.
Just press the w key. From the help available with F1: w: wrap process command in multiple lines
How to configure htop to display the complete command line?
1,301,568,488,000
Given the option: [ ] Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest) In htop (Version 1.0.1) what are the meanings of the colours? In the following image, I'm seeing rather a lot of what I expect is IO-Wait, but where does one determine the meaning of the colours. Naturally this depends on the htop colour theme in use (default) and the terminal color scheme (solarized light here), but is there a reference? Note: This normally happens to my server right before it dies, so I thought I'd ask whilst I have some time waiting for the box to recover.
F1 or h will show you the legend. It looks like in this color scheme: CPU: blue is for low priority threads green is normal priority threads black is for io-wait see below for more. Memory: green is memory in use blue is buffer orange is cache
Meaning of colours in htop
1,301,568,488,000
There are a few questions and answers on here with regard to being alerted when a process completes/exits(1, 2) – but these all assume that the user has issued said process themselves, and thus can script it with an alert built into the governing script, or pipe the process to some kind of alert. My situation is that I would like to be alerted of the completion/exit of a process that my user is not initializing. Namely, I am bulk processing massive video files on a Ubuntu 12.04 LTS server. Certain operations on these files take a very long time, so I would like some kind of alert (email would be great) when a specific one finishes. They take so long, that doing this on a one-off basis, manually, based on PIT would be perfectly fine. To provide more info – let's say I'm processing a particularly big file, and I see that it has progressed on to an FFMPEG script, the process itself being a python script (that is quite complex, and not written by myself, and something I do not wish to modify – though that would be the first logical approach). I imagine issuing a command or script with the PID of said running python script as an argument, and when the process with that PID is no longer running, the alert script does its thing. Any ideas?
I wrote process_watcher.py process_watcher --pid 1234 --to [email protected] Currently, email body looks like: PID 18851: /usr/lib/libreoffice/program/soffice.bin --writer --splash-pipe=5 Started: Thu, Mar 10 18:33:37 Ended: Thu, Mar 10 18:34:26 (duration 0:00:49) Memory (current/peak) - Resident: 155,280 / 155,304 kB Virtual: 1,166,968 / 1,188,216 kB [+] indicates the argument may be specified multiple times, for example: process-watcher -p 1234 -p 4258 -c myapp -c "exec\d+" --to [email protected] --to [email protected] optional arguments: -h, --help show this help message and exit -p PID, --pid PID process ID(s) to watch [+] -c COMMAND_PATTERN, --command COMMAND_PATTERN watch all processes matching the command name. (RegEx pattern) [+] -w, --watch-new watch for new processes that match --command. (run forever) --to EMAIL_ADDRESS email address to send to [+] -n, --notify send DBUS Desktop notification -i SECONDS, --interval SECONDS how often to check on processes. (default: 15.0 seconds) -q, --quiet don't print anything to stdout Ceate a GitHub issue if you need any improvements to it.
Alert when running process finishes
1,301,568,488,000
I have a regular process that's not so important but will consume very much CPU power. I have another process which is really important, but it spends most of the time idle, but when it gets a job it really needs high computing power. I tried running with nice -20 ./low_priority_process and nice --20 ./high_priority_process but still the lower priority process consumes significant amount of CPU when the high priority process is in need. How can I run a process that will really yield or even auto-suspend when another process is using CPU power?
Have a look at cgroups, it should provide exactly what you need - CPU reservations (and more). I'd suggest reading controlling priority of applications using cgroups. That said, put the important yet often idle processes into group with allocated 95% of CPU and your other applications into another one with allocated 5% - you'll get (almost) all of the power for your jobs when needed, while the constantly power hungry process will only get 5% at most at those times. When the computational surges disappear all CPU performance will be thrown at the remaining processes. As a benefit, if you create a special cgroup (with minimal performance requirements) for processes like sshd, you'll be able to log in no matter what is trying to get all CPU it can - some CPU time will be reserved for sshd.
Run Linux process at very very low priority?
1,301,568,488,000
How can I show the CPU usage side by side rather than a list? I have this : but I want to show it like this:
Go to settings (F2), under Meters, you select what is in the left column and what in the right column. Instead of CPUs (1/1) in the left column, select CPUs (1/2) for the left column and CPUs (2/2) for the right column. F10 to save the changes and it's done.
htop, show cpu side by side
1,301,568,488,000
htop allows me to nicely see trees of processes within the shell. I can kill processes by pressing F9 (KILL) and then selecting which signal (e.g. 15 SIGTERM) I want to send to a job to kill. However, this only allows me to kill one process at a time. Is there a way to kill a full tree of processes using htop?
From man htop: INTERACTIVE COMMANDS Space Tag or untag a process. Commands that can operate on multiple processes, like "kill", will then apply over the list of tagged processes, instead of the currently highlighted one. U Untag all processes (remove all tags added with the Space key). F9, k "Kill" process: sends a signal which is selected in a menu, to one or a group of processes. If processes were tagged, sends the signal to all tagged processes. If none is tagged, sends to the currently selected process. Not quite the answer you were looking for, but close. You can also eliminate process groups or children with kill, see: https://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes
Killing a tree of processes in top/htop
1,301,568,488,000
I want to monitor only a process and its children processes on htop. Filtering on the name of the parent process lists only the parent process, not its children. How do I show the children processes too?
Under Linux, you can do: htop -p `pstree -p $PID | perl -ne 'push @t, /\((\d+)\)/g; END { print join ",", @t }'` where $PID is the root process. This works as follows: The list of the wanted processes are obtained with pstree, using the -p option to list them with their PID. The output is piped to a Perl script that retrieves the PID's, using a regular expression (here, \((\d+)\)), and outputs them separated with commas. This list is provided as an argument of htop -p. For other OS like Mac OS, you may need to adapt the regular expression that retrieves the PIDs. Note: It is unfortunately not possible to update the list with new children that are spawn later, because once htop has been executed, one cannot do anything else. This is a limitation of htop (current version: 2.0.2).
How to display only a process and its descendant processes on htop?
1,301,568,488,000
Why do the progress meters across the top of the screen in htop show CPU usage consistently above >90% while the numbers in the table below show a nearly idle system with CPU usage and load average at 0.0%?
htop is unaware it is running on a kernel level virtualized environment (Dreamhost VPS is using VServer technology). It is then showing the CPU usage for all the OS instances sharing the same kernel, not just yours. Have a look to vtop output which sho ws all processes sharing the CPUs, not just the ones in your container. If vtop is not installed, and this is probably expected for a commercial solution as one wouldn't like to a customer to see what processes are running other customers, there is no way to fix the issue from inside your container, unless patching top source to compute CPU usage instead of getting it from the kernel statistics. It might do it by summing up CPU usage of all the processes running in your VServer, e.g.: ps aux | awk ' {cpu+=$3; ram+=$6} END {printf("cpu: %d%%, RAM: %.2f MiB\n",cpu,ram/1024) }'
why does htop meter show >90% while table is 0.0%?
1,301,568,488,000
My system was running slow recently and I checked htop to identify resource consumption. RES Column is 213M which is quite normal for chrome. I was surprised after looking at VIRT column, Google Chrome was taking 1.1T !!! I killed chrome and open again and still it was using 1.1T VIRT memory. Any pointer would be helpful if Higher VIRT is not normal and need to be fixed. Laptop Hardware details. Processor Intel® Core™ i3-4005U CPU @ 1.70GHz × 4 Graphics NVD7 / Intel® HD Graphics 4400 (HSW GT2) Memory 7.7 GiB Disk Capacity 740.2 GB // uname -srvmpio Linux 5.13.0-41-generic #46~20.04.1-Ubuntu SMP Wed Apr 20 13:16:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux // Google Chrome version Version 102.0.5005.61 (Official Build) (64-bit)
Please disregard VIRT. I've never used or seen anyone use or pay attention to it ever. It basically means nothing. No idea why top/htop still show it. Mugurel Sumanariu once wrote about it: VIRT stands for the virtual size of a process, which is the sum of memory it is actually using, memory it has mapped into itself (for instance the video card’s RAM for the X server), files on disk that have been mapped into it (most notably shared libraries), and memory shared with other processes. VIRT represents how much memory the program is able to access at the present moment. (On a system where memory overcommit is disabled it could mean something but you wouldn't want to use such a system).
Why Google Chrome is reserving Terabytes scale virtual memory?
1,301,568,488,000
I'm trying to get an accurate read of my used CPU (in percent) from top. This is the command I'm running for testing: top -n1 | awk '/Cpu\(s\):/ {print $2}' This returns: 10.7%us, Which is the proper piece of data I want. However, every time I run the command I get the same output, even though I am applying different loads on my system (and not to mention htop tells me my usage is different). It seems that whenever I start top, my CPU usage is the same. Only after a couple of frames does it give me proper values. It doesn't seem like I can parse top's output this way, so I'm looking for other reliable applications which will give me an accurate reading from the shell. I really like how htop can give me a per-core reading. I've tried iostat and mpstat but they seem to give inaccurate and "slow to change" values.
I use this script (from this thread on the Arch boards): #!/bin/bash read cpu a b c previdle rest < /proc/stat prevtotal=$((a+b+c+previdle)) sleep 0.5 read cpu a b c idle rest < /proc/stat total=$((a+b+c+idle)) CPU=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
How can I receive top-like CPU statistics from the shell?
1,301,568,488,000
I have a htpc/server-ish ubuntu box running at home with kodi (xbmc) and some other webservices. I noticed kodi was laggish and ssh'ed into the box to see what was going on. I saw this htop output: This is the output of free -m richard@RMD-HTPC:~$ free -m total used free shared buffers cached Mem: 7642 7505 137 152 196 1296 -/+ buffers/cache: 6012 1630 Swap: 1905 10 1895 How come the ram usage is at 6000 of 7600mb in the screenshot at 7505 in free But when I add up all the percentages of the unique processes in htop I only go to about 22-25% ? Should it not be much higher?
It is because htop is counting buffers and cached memory as free memory, because it can actually can be seen this way. There is no "cost" in having some cached data in memory, so the kernel keep stuff there just in case it needs afterwards. For instance, suppose you have watched a video of about 500mb, after you close the video, the kernel may decide to keep it in memory instead of cleaning that part, just in case you need that video again so it doesn't need to load it again from your slow HDD. But that 500mb can be considered free, because as soon as you need memory for something else, the kernel will be able to use that memory right away. It is not the case when that memory is being used by a running program, because that program is using that memory right now. If you subtract from the used memory the buffers and cached values, you will get the value displayed by htop. Now about that percentage you said, it depends on how you have summed up.
How to interpreted top/htop memory usage
1,301,568,488,000
I've read that the color red indicates "kernel processes." Does that mean little daemons that are regulating which task gets to use the CPU? And by extension, transaction costs in an oversubscribed system? I'm running some large-scale geoprocessing jobs, and I've got two scripts running in parallel at the same time. The first script does the actual processing, on all 96 cores. It is responsible for almost all of the memory use. The second script uses curl to download the data to feed the first process, and it does so in parallel. I wrote it to download only until there are n_cores * 3 files downloaded. If that constraint isn't met, it waits for a minute or so and then check again. So, most of the time it isn't running -- or rather it is executing the Sys.sleep() command in R. I've experimented with using fewer cores for the downloading process. When I do so, it can't keep up with the processing script (I'm DLing from S3). TL;DR: Would my processes run faster if I could make htop less red? And are they red because there are more processes than cores?
Red represents the time spent in the kernel, typically processing system calls on behalf of processes. This includes time spent on I/O. There’s no point in trying to reduce it just for the sake of reducing it, because it’s not time that’s wasted — it’s time that’s spent by the kernel doing useful stuff (as long as you’re not thrashing, so look at the number of context switches etc.). I've experimented with using fewer cores for the downloading process. When I do so, it can't keep up with the processing script (I'm DLing from S3). suggests that your current setup is evenly balanced between the I/O needed to feed the processing, and the processing itself, which is a rather nice result. If you suspect that you’ve got too many processes running, and that that’s causing waste (by thrashing), then you could try reducing the number of geoprocessing jobs, to see if your overall throughput increases. The usual benchmarking tips apply: identify what you’re going to tweak, determine what resulting variations could occur and what they mean, only tweak one thing at a time, and measure everything.
Lots of red in htop -- does that mean my tasks are tripping over each other?
1,301,568,488,000
I'm trying to use htop in tty1. However, some of the function keys don't appear to work as normal. F1 and F2 do nothing, and F3 seems to trigger setup (which should normally be triggered by F2). In addition, F4 and F5 don't work. Also, when I try and press Esc to get out of these screens, I have to press it twice. In a normal terminal (terminator), the function keys work fine. However, I have to press Esc twice here too, so perhaps that's a red herring. How can I use these function keys in tty1? EDIT In tty1, if I press Ctrl+v then F1 to F5, etc. I get the the following output: ^[[[A ^[[[B ^[[[C ^[[[D ^[[[E In terminator, I get ^[OP ^[OQ ^[OR ^[OS ^[[15~ The function keys above this are equivalent (e.g. ^[[17~ for F6). EDIT 2 In response to Stéphane Chazelas's comment. $TERM is the same in tty1 as in my "normal", working terminal. It is xterm-256color. I am not using screen or tmux. I am using htop 1.0.3, although my first edit seems to point to it being an issue upstream of htop. "Does infocmp -L1 | grep key_f match what those keys send for you? I'm not sure what you mean by "match what those keys send for you", but I ran this command in both my normal terminal and tty1, and the output was identical, as below. key_f1=\EOP, key_f10=\E[21~, key_f11=\E[23~, key_f12=\E[24~, key_f13=\E[1;2P, key_f14=\E[1;2Q, key_f15=\E[1;2R, key_f16=\E[1;2S, key_f17=\E[15;2~, key_f18=\E[17;2~, key_f19=\E[18;2~, key_f2=\EOQ, key_f20=\E[19;2~, key_f21=\E[20;2~, key_f22=\E[21;2~, key_f23=\E[23;2~, key_f24=\E[24;2~, key_f25=\E[1;5P, key_f26=\E[1;5Q, key_f27=\E[1;5R, key_f28=\E[1;5S, key_f29=\E[15;5~, key_f3=\EOR, key_f30=\E[17;5~, key_f31=\E[18;5~, key_f32=\E[19;5~, key_f33=\E[20;5~, key_f34=\E[21;5~, key_f35=\E[23;5~, key_f36=\E[24;5~, key_f37=\E[1;6P, key_f38=\E[1;6Q, key_f39=\E[1;6R, key_f4=\EOS, key_f40=\E[1;6S, key_f41=\E[15;6~, key_f42=\E[17;6~, key_f43=\E[18;6~, key_f44=\E[19;6~, key_f45=\E[20;6~, key_f46=\E[21;6~, key_f47=\E[23;6~, key_f48=\E[24;6~, key_f49=\E[1;3P, key_f5=\E[15~, key_f50=\E[1;3Q, key_f51=\E[1;3R, key_f52=\E[1;3S, key_f53=\E[15;3~, key_f54=\E[17;3~, key_f55=\E[18;3~, key_f56=\E[19;3~, key_f57=\E[20;3~, key_f58=\E[21;3~, key_f59=\E[23;3~, key_f6=\E[17~, key_f60=\E[24;3~, key_f61=\E[1;4P, key_f62=\E[1;4Q, key_f63=\E[1;4R, key_f7=\E[18~, key_f8=\E[19~, key_f9=\E[20~,
By setting: export TERM=xterm-256color you're telling htop (and every other visual terminal application that uses the termcap or terminfo database) that your terminal is a 256 colour xterm and not a Linux virtual console. htop will query the terminfo database to know what sequence of characters is sent upon F1, F2... but will get those for xterm. xterm sends different sequences than the Linux virtual console for those keys which you can verify by querying the terminfo database by hand with infocmp for instance: $ infocmp -L1 xterm-256color | grep 'key_f[1-5]=' key_f1=\EOP, key_f2=\EOQ, key_f3=\EOR, key_f4=\EOS, key_f5=\E[15~, $ infocmp -L1 linux | grep 'key_f[1-5]=' key_f1=\E[[A, key_f2=\E[[B, key_f3=\E[[C, key_f4=\E[[D, key_f5=\E[[E, So htop will not recognise \E[[A as a F1, it will expect \EOP for that. Here, you don't want to assign values to $TERM in ~/.bashrc. $TERM should be set by the terminal emulators (xterm, terminator) themselves, and by getty for Linux virtual consoles (should be linux there). If you're not happy with the value that a particular terminal emulator picks for $TERM, that's the configuration of that terminal emulators you should update.
How can I pass function keys to htop in a tty?
1,301,568,488,000
The following three outputs were taken essentially simultaneously: top: top - 02:54:36 up 2 days, 13:50, 3 users, load average: 0.05, 0.05, 0.09 Tasks: 181 total, 1 running, 179 sleeping, 0 stopped, 1 zombie %Cpu(s): 2.5 us, 0.8 sy, 0.0 ni, 96.6 id, 0.1 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 16158632 total, 11234480 used, 4924152 free, 844 buffers KiB Swap: 16777212 total, 0 used, 16777212 free, 10640832 cached free -h: total used free shared buffers cached Mem: 15G 10G 4.7G 0B 844K 10G -/+ buffers/cache: 578M 14G Swap: 15G 0B 15G htop: free and top seem to agree. In top there is 11234480 KiB used, subtracting 10640832 KiB cached gives 579.7 MiB, which is pretty close to what free reports under used +/- buffers/cache. However htop is reporting 1836 (MiB) used, which is neither here nor there as far as I can see. Where does this difference come from? htop is clearly not including the cached data, but it is still reporting more than three times the memory usage of free or top. I am aware that there are many similar questions, but I haven't come across one that explains this discrepancy (the confusion usually seems to be only the with/without cache counting). Edit: I should mention that I am running openSUSE, and I see the same kind of discrepancy in both version 12.2 and 12.3 RC1. Edit2: The included version of htop is 1.0.1. I have also compiled version 1.0.2 from source and see the same discrepancy then as well.
A complete re-write of my previous post. Got a bit curious and checked out further. In short: the reason for the difference is that openSUSE uses a patched version of top and free that adds some extra values to `cached'. A) Standard version top, free, htop, ...: Usage is calculated by reading data from /proc/meminfo: E.g.: #free: Row Column | Corresponding /proc/meminfo entry -----|--------|---------------------------------- Mem: total : MemTotal used : MemTotal - MemFree free : MemFree shared : MemShared buffers : Buffers cached : Cached -----|--------|---------------------------------- -/+ buffers/cache: used : (MemTotal - MemFree) - (Buffers + Cached) free : MemFree + (Buffers + Cached) #htop: Used U* : ((MemTotal - MemFree) - (Buffers + Cached)) / 1024 *I'm using the name Used U for memory used by User Mode. Aka Used minus (Cached + Buffers). So in reality same calculation is used. htop display the following in the memory meter: [Used U % of total | Buffers % of total | Cached % of total ] UsedU MB (MB is actually MiB.) B) Patched version The base for free and top on Debian, Fedora, openSuse is is procps-ng. However, each flavour add their own patches that might, or migh not become part of the main project. Under openSUSE we find various additions to the top/free (procps) package. The ones to take notice of here is some additional values used to represent the cache value. (I did not include these in my previous post as my system uses a "clean" procps.) B.1) Additions In /proc/meminfo we have Slab which is in-kernel data structure cache. As a sub category we find SReclaimable which is part of Slab that might be reclaimed for other use both by Kernel and User Mode. Further we have SwapCached which is memory that once was swapped out, is swapped in but also is in the swap-file. Thus if one need to swap it out again, this is already done. Lastly there is NFS_Unstable which are pages sent to the server but not yet committed to stable storage. The following values are added to cache in the openSUSE patched version: SReclaimable SwapCached NFS_Unstable (In addition there are some checks that total has to be greater then free, used has to be greater then buffers + cache etc.) B.2) Result Looking at free, as a result the following values are the same: total, used, free and buffers. The following are changed: cached and "+/- buffers". used = MemTotal - MemFree old: cached : Cached +-/buffers-used: used - (Buffers + Cached) +/-buffers-free: free + (Buffers + Cached) patched: cached : Cached + SReclaimable + SwapCached + NFS_Unstable +/-buffers-used: used - (Buffers + Cached + SReclaimable + SwapCached + NFS_Unstable) +/-buffers-free: free + (Buffers + Cached + SReclaimable + SwapCached + NFS_Unstable) The same additions are done to top. htop is unchanged and thus only aligning with older / or un-patched versions of top / free.
htop reporting much higher memory usage than free or top
1,301,568,488,000
How to display meminfo in megabytes in top? discusses how to change the units of memory (e.g. megabytes, gigabytes, etc.) when using top. Is there a way to do this in htop as well? man htop doesn't address this, neither does it seem evident from the info displayed via F1 when running the program. Alternatively, if there were at least a way to change the threshold at which htop automatically switches from one unit to another, that would work. E.g. right now, it will display memory in terms of 4406M which I find quite difficult to read at a glance in a long line of processes. So, if I could just get it to not go above hundreds of units, and thus automatically switch this to, e.g. 4.4G, when it goes above 999M then that would work too.
I don't think it is possible, but, if you are up for building your own htop, not impossible. The code is at github and if you look at Meter.c you will see the logic they use to decide what to display.
htop - change units for memory usage display
1,301,568,488,000
I'm using Debian 9 to host a game server. Specifically, I'm hosting about 10 instances of the game Don't Starve Together. The other day I noticed one of those instances (which was getting a lot of player activity) exhibit performance issues. When I loaded up htop I saw that CPU% was reporting 101% but the bar graphs at the top were not showing any cores at much above 50%. To my knowledge, CPU% shows a sum of the percentages used of each core by a process, so exceeding 100% is normal and no core being above 50% is also normal (it just means the process is quite multi-threaded), however I believe Don't Starve Together is almost entirely a single-threaded application (with minimal multi threading for networking). One of the bar graphs at the top should be at least over 90%, but none are. Why isn't one of the bar graphs at the top not over 90%? My processor is an i7-6700K (4 core, 8 thread - spec sheet )
Over time, the operating system schedules threads on different CPU cores, so the 101% reported for your processes are potentially distributed over all 8 bars.
htop CPU% at ~100% but bar graph shows every core much lower
1,301,568,488,000
On my computer it shows Tasks 314; 24 running What do these numbers mean? Is 1 Task = 1 process? Why isn't the number of running tasks = number of CPUs then? (I have more than 24 CPUs) edit. sometimes the number before "running" actually exceeds the number of CPUs I have!
Tasks do represent the number of opened processes. (Note that I do not use the term "running" to avoid confusion.) You have to realize that not all opened processes consume CPU constantly. Each process can be in a number of different states: running: actively using CPU stopped: the process was stopped (paused) by the user defunc or zombie: process is actually blocking on an external resource, commonly a disk drive sleeping: most common state as many processes actually sleep a lot of the time and do small checks at different intervals, or wait for user input
What is the meaning of Tasks and Running in htop screen?
1,301,568,488,000
My server is running on debian Wheezy and htop 1.0.1 but it does not display any values on the meters bar except the 100.0% value of CPUs. Is it possible to show always the values of a meter? This is the current display of htop on my server: But I want to have the numbers always on my meters like on this screenshot from https://hisham.hm/htop/index.php?page=screenshots: My htoprc is located in ~/.config/htop/htoprc and contains the following data: # The parser is also very primitive, and not human-friendly. fields=0 48 17 18 38 39 40 2 46 47 49 1 sort_key=46 sort_direction=1 hide_threads=0 hide_kernel_threads=1 hide_userland_threads=0 shadow_other_users=0 show_thread_names=0 highlight_base_name=1 highlight_megabytes=1 highlight_threads=0 tree_view=0 header_margin=1 detailed_cpu_time=0 cpu_count_from_zero=0 color_scheme=0 delay=15 left_meters=LeftCPUs2 CPU Memory Swap left_meter_modes=1 1 1 1 right_meters=RightCPUs2 Tasks LoadAverage Uptime right_meter_modes=1 2 2 2
Well, you create a htoprc file, mine is located in ~/config/htop/htoprc, I don't know how it is under Ubuntu, but that should work too. inside you just have to put: left_meters=AllCPUs Memory Swap left_meter_modes=1 1 1 That should give you the output you want. You can also change the number of the color_scheme. Maybe the background is the same color as the numbers.
Display numbers in meters of htop
1,301,568,488,000
In htop I can use / to search for terms, and typically when searching in tools like less and vi, I can use n or N to show the various instances of results that I find, but this doesn't work in htop. Does anyone know how to show next and previous results when searching in htop? Thanks!
You can use F3 Search key to go to next occurrence of the search item. This works regardless of whether you initiate the search with / or F3. Just be sure to avoid pressing Return or else F3 will start a new search instead of continuing the previous one.
How to cycle through htop search results
1,301,568,488,000
I use recoll to index files and it kicks in a inopportune times. When I use htop to change the view to a tree view using F5 and filter the process list I see a master process running and child processes underneath it. When I press F9 to choose a termination option it doesn't seem to respond to the SIGTERM option so I have to use the SIGKILL option. Is there an option to pause or stop the parent process and all its children rather than kill it outright?
You can press Space to tag a process. The kill command applies to all tagged processes. There's no easy way to tag a process and its children, but the tree view (t) should list them contiguously. Depending on how recoll is run, the processes may be in their own process group. If they are, then you can use kill -STOP -1234 to suspend them all, where 1234 is the process group ID (usually but not necessarily the process ID of the initial process in the group). You can check with ps -o pid,ppid,pgid,comm -C recoll, then ps -o pid,ppid,pgid,comm ww | grep -v recoll to see if there are any other processes in the process group. Htop doesn't have an interface to process groups. If all the processes are called recoll, then an easier method is to filter the processes by name. In htop, use the filter command, then you can easily tag the processes you want to kill. On the command line, run ps $(pgrep recoll) to list the matching processes. If you're happy with the list, run pkill -STOP recoll to suspend those processes.
How can htop be used to suspend a process and all its child processes?
1,301,568,488,000
When using top, it shows me that cifsd has used lots of CPU time but in htop the process does not show up at all. I have tried enabling threads (with H) in htop, to no avail. It also does not show up in pstree, even when using parameters that might show me more info (-apcls). I can find its process id in /proc so it exists. In ps aux it shows up but in square brackets: [cifsd] is the value of the last column (titled COMMAND). What kind of a process is this? From the CPU time over uptime, it seems to use 7.8% CPU on average (and it's pretty constant, when looking at top), so it's definitely a process of interest, but htop hides it.
Go to setup and change your 'Display' options: F2 > Display options Do not hide kernel threads and show custom thread names: [ ] Hide kernel threads [x] Show custom thread names Save: F10
htop does not show a process
1,301,568,488,000
Does anyone know of a way to change the scale of the bar graphs in htop? The memory one, specifically, doesn't seem based off of percent of memory used--it's some other scale that seems useless to me. It looks like this: Mem[|||||||||||||||||||||||||||||||||||||||||||| 1978/7847MB] When it should look like this: Mem[|||||||||| 1978/7847MB] ...to reflect the correct ratio of memory usage. I am under the impression htop is highly customizable, but I'm not sure how to do this.
Don't you have colors? Green Blue Orange Mem[|||||||||||||||||||||||||||||||||||||||||||| 1978/7847MB] Where green should be 1978 MiB. Else you can enter F2 -> Under setup stay on "Meters" -> Right arrow to get to "Left column". -> Down 1 to get to "Memory Bar". Then press enter to view various ways of display. When it comes to what the bar displays it is like this. It reads /proc/meminfo and show - colors depend on "Colors" setting - this is default: Used U (green): (MemTotal - MemFree) - (Buffers + Cached) / 1024 And then the percentage of MemTotal of that. Bar: Green Blue Orange/Yellow [Used U % of total | Buffers % of total | Cached % of total ] Used U / Toatal MB Also see here. I have a script some where that makes it as well. Have to look for it.
Change the scale of the bar graph in htop
1,301,568,488,000
I am running a Debian Jessie and having memory issues when using Google Chrome I tried disabling extensions, disabling cache, flushing the cache, and disabling the web 3d rendering, but nothing really improves. I am getting huge lags some times and I am really wondering where this is coming from.
If you add up MEM% for all the identical looking chrome processes, then you have well over 100%, which is impossible. That's because those are not, in fact, separate processes, they're threads, which share the same memory space. htop shows these by default, but see here for how to change that and get a view that will make more sense to you. Your total used RAM is 1047 of 1727 MB, so you do not have memory problems. When looking at memory stats, keep in mind that virtual memory, more properly: virtual address space, shown here as VIRT is not real memory. It's address space, and most of the addresses aren't used and don't correspond to anything. On linux, the size of this pretend space can be up to 4 GB per process, even if you don't have that much available to start with. A decent metric of the amount of RAM actually consumed is the RSS or resident memory size (in htop's case, RES). If you eliminate threads from the view, you'll see there's actually only one 142 MB google-chrome process (actually there may be a handful of genuinely separate chrome processes, but not dozens). Another significant stat if you are trying to diagnose system performance problems is the amount of CPU time consumed (TIME+), but again nothing looks particularly out of line here WRT chrome.
How to reduce chrome's virtual memory usage?
1,301,568,488,000
Whenever I open htop, it shows CPU usage suddenly shooting up to 100% on a singe core. I take it gathering statistics for htop is not that intensive?! Why does htop suddenly show this spike?
You're seeing a side effect of the program seeing its loading resource usage. Loading an executable and its libraries into memory, initializing and turning control over to program is not a free operation: it involves the CPU, memory and (if it hasn't been cached) disk. Here's top showing its usage immediately upon starting: top - 13:21:29 up 1 day, 23:31, 1 user, load average: 1.73, 1.78, 1.46 Tasks: 151 total, 3 running, 93 sleeping, 0 stopped, 0 zombie %Cpu(s): 16.4 us, 5.7 sy, 0.0 ni, 73.1 id, 4.6 wa, 0.0 hi, 0.2 si, 0.0 st KiB Mem : 3967564 total, 135908 free, 2053480 used, 1778176 buff/cache KiB Swap: 8388604 total, 8332796 free, 55808 used. 1652564 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 896 qemu 20 0 1961872 508076 6144 S 100.0 12.8 790:22.87 /usr/bin/qemu-system-x86_64 -name guest=Gentoo-amd64,debug-threads=on + 596 qemu 20 0 2326244 863164 4488 R 6.2 21.8 311:23.29 /usr/bin/qemu-system-x86_64 -name guest=data,debug-threads=on -S -obje+ 12655 root 20 0 49732 4164 3432 R 6.2 0.1 0:00.01 top -d 10 1 root 20 0 49568 5492 3700 S 0.0 0.1 0:02.52 /lib/systemd/systemd --switched-root --system --deserialize 32 After 10 seconds (it's the same for smaller periods, but I wanted to be able to copy the text at startup): 896 qemu 20 0 1961872 508076 6144 R 103.5 12.8 790:33.23 /usr/bin/qemu-system-x86_64 -name guest=Gentoo-amd64,debug-threads=on + 596 qemu 20 0 2326244 863164 4488 R 8.7 21.8 311:24.16 /usr/bin/qemu-system-x86_64 -name guest=data,debug-threads=on -S -obje+ 10200 root 20 0 1354396 131740 29824 S 3.1 3.3 13:05.97 python2.7 /usr/share/virt-manager/virt-manager 10150 root 20 0 66548 6004 4880 S 2.6 0.2 8:22.49 sshd: root@pts/0 850 qemu 20 0 1726656 300432 5496 S 0.8 7.6 19:30.70 /usr/bin/qemu-system-x86_64 -name guest=distcc-i686,debug-threads=on -+ 328 avahi 20 0 53744 3608 2936 S 0.2 0.1 0:10.93 avahi-daemon: running [server-calgary.local] 460 root 20 0 0 0 0 S 0.1 0.0 0:04.87 [nfsd] 475 root 20 0 1282444 13820 8268 S 0.1 0.3 1:13.16 /usr/sbin/libvirtd --listen 9143 root 20 0 0 0 0 I 0.1 0.0 0:36.05 [kworker/1:1] 10146 root 20 0 0 0 0 I 0.1 0.0 0:25.93 [kworker/0:2] 12641 root 20 0 0 0 0 I 0.1 0.0 0:00.02 [kworker/u4:0] 12655 root 20 0 49732 4176 3432 R 0.1 0.1 0:00.02 top -d 10 1 root 20 0 49568 5492 3700 S 0.0 0.1 0:02.52 /lib/systemd/systemd --switched-root --system --deserialize 32 Does top really use 6.2% of the CPU to do its work? No: that's the loading work that all programs will have at startup. Usage goes down to 0.1% after the program has settled down. It's unlikely that htop is using 100% of a CPU (there's possibly a bug there), but it's not strange that it has higher usage when starting either.
Why does htop shoot to 100% CPU upon opening?
1,301,568,488,000
I recently see that there is new "I/O" (blue one) on htop, how to switch to that tab?
OK found it XD literally Tab or Shift+Tab from https://man7.org/linux/man-pages/man1/htop.1.html
How to switch htop tab?
1,301,568,488,000
I am using Ubuntu 20.04 LTS. The kernel version is 5.4.0-42. Here is an example program: // mre.c // Compile with: cc -o mre mre.c -lSDL2 #include <stdio.h> #include <SDL2/SDL.h> int main(void) { SDL_Init(SDL_INIT_VIDEO); // Doesn't work without SDL_INIT_VIDEO getchar(); } When I look at the running program ./mre in htop with thread names turned on, I see it has these four threads: mre:disk$3 mre:disk$2 mre:disk$1 mre:disk$0 And here are some threads of /usr/libexec/ibus-x11 with similar names: ibus-x1:disk$3 ibus-x1:disk$2 ibus-x1:disk$1 ibus-x1:disk$0 Many programs don't have them (maybe they aren't using a certain graphical interface?) Such threads always come in fours (my computer has four cores) and are listed in descending order. /usr/lib/xorg/Xorg has eight of these threads, two of each number 0-3. What are they for?
Those threads are used for the mesa disk cache: util_queue_init(&cache->cache_queue, "disk$", 32, 4, UTIL_QUEUE_INIT_RESIZE_IF_FULL | UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY | UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY); https://sources.debian.org/src/mesa/22.0.3-1/src/util/disk_cache.c/?hl=174#L174 And inside util_queue_init() then: /* Form the thread name from process_name and name, limited to 13 * characters. Characters 14-15 are reserved for the thread number. * Character 16 should be 0. Final form: "process:name12" * * If name is too long, it's truncated. If any space is left, the process * name fills it. */ https://sources.debian.org/src/mesa/22.0.3-1/src/util/u_queue.c/?hl=405#L414-L420 Thus, all GUI processes that somehow call into that mesa code create those extra threads, e.g. on a f33 desktop system of mine: pid tid comm cls 1942 1989 gnome-s:disk$0 BAT 1942 1990 gnome-s:disk$1 BAT 1942 1991 gnome-s:disk$2 BAT 1942 1992 gnome-s:disk$3 BAT 2041 2237 Xwaylan:disk$0 BAT 2041 2238 Xwaylan:disk$1 BAT 2041 2239 Xwaylan:disk$2 BAT 2041 2240 Xwaylan:disk$3 BAT 2041 2259 Xwaylan:disk$0 BAT 2041 2260 Xwaylan:disk$1 BAT 2041 2261 Xwaylan:disk$2 BAT 2041 2262 Xwaylan:disk$3 BAT 2292 2325 gsd-xse:disk$0 BAT 2292 2326 gsd-xse:disk$1 BAT 2292 2327 gsd-xse:disk$2 BAT 2292 2328 gsd-xse:disk$3 BAT 2307 2344 ibus-x1:disk$0 BAT 2307 2345 ibus-x1:disk$1 BAT 2307 2346 ibus-x1:disk$2 BAT 2307 2347 ibus-x1:disk$3 BAT 2464 2578 firefox:disk$0 BAT 2464 2579 firefox:disk$1 BAT 2464 2580 firefox:disk$2 BAT 2464 2581 firefox:disk$3 BAT 2756 2785 firefox:disk$0 BAT 2756 2786 firefox:disk$1 BAT 2756 2787 firefox:disk$2 BAT 2756 2788 firefox:disk$3 BAT 2806 2841 firefox:disk$0 BAT 2806 2842 firefox:disk$1 BAT 2806 2843 firefox:disk$2 BAT 2806 2844 firefox:disk$3 BAT 2919 3078 firefox:disk$0 BAT 2919 3079 firefox:disk$1 BAT 2919 3080 firefox:disk$2 BAT 2919 3081 firefox:disk$3 BAT 3346 3367 firefox:disk$0 BAT 3346 3368 firefox:disk$1 BAT 3346 3369 firefox:disk$2 BAT 3346 3370 firefox:disk$3 BAT 3408 3426 firefox:disk$0 BAT 3408 3427 firefox:disk$1 BAT 3408 3428 firefox:disk$2 BAT 3408 3429 firefox:disk$3 BAT 5794 5825 firefox:disk$0 BAT 5794 5826 firefox:disk$1 BAT 5794 5827 firefox:disk$2 BAT 5794 5828 firefox:disk$3 BAT 6345 6364 firefox:disk$0 BAT 6345 6365 firefox:disk$1 BAT 6345 6366 firefox:disk$2 BAT 6345 6367 firefox:disk$3 BAT 9502 9525 firefox:disk$0 BAT 9502 9526 firefox:disk$1 BAT 9502 9527 firefox:disk$2 BAT 9502 9528 firefox:disk$3 BAT 22548 22565 firefox:disk$0 BAT 22548 22566 firefox:disk$1 BAT 22548 22567 firefox:disk$2 BAT 22548 22568 firefox:disk$3 BAT 33788 33807 vlc:disk$0 BAT 33788 33808 vlc:disk$1 BAT 33788 33809 vlc:disk$2 BAT 33788 33810 vlc:disk$3 BAT 48178 74574 kwallet:disk$0 BAT 48178 74575 kwallet:disk$1 BAT 48178 74576 kwallet:disk$2 BAT 48178 74577 kwallet:disk$3 BAT 60824 60830 chromiu:disk$0 BAT 60824 60831 chromiu:disk$1 BAT 60824 60832 chromiu:disk$2 BAT 60824 60833 chromiu:disk$3 BAT 69502 69519 firefox:disk$0 BAT 69502 69520 firefox:disk$1 BAT 69502 69521 firefox:disk$2 BAT 69502 69522 firefox:disk$3 BAT
What are these threads named disk$0, disk$1, etc.?
1,301,568,488,000
I'm using zsh on macOS 12.4, apple M1. When I run htop normally using the command htop and use ctrl+z it behaves as expected and sends the process to the background. I can evoke it again using the fg command and after that send it again to the background using ctrl+z However, when I run htop and send it to the background directly using the command htop & and evoke it using fg, ctrl+z no longer sends it to the background. ctrl+z has no effect whatsoever. Is this expected? I am not running into the same issue when I use vim &.
I can reproduce it on Ubuntu with htop and some other ncurses-based applications like mutt. At the root of the issue is the fact that when zsh's line editor (zle) is active all the VQUIT, VSUSP, VDSUSP, VSWTCH, VLNEXT special characters in the tty device discipline are disabled, so that upon pressing Ctrl+Z, zle receives a ^Z instead of the system trying to send a SIGTSTP to the foreground process group (VSUSP setting). You can see it there in the code. When zsh leaves the line editor and a command is run (or a job is put back in foreground), the terminal state is restored (including with SUSP restored as ^Z if that's what it was before). Now when you start htop & a TUI application, you reenter the line editor straight away (back to the prompt) while htop initialises in background. htop and ncurses applications in general do the same kind of thing as zle does: they retrieve the initial tty settings, change them to adapt to their own use and upon exit (or suspension) restore the saved tty settings. Now the problem is that when started in background, the initial tty settings that the ncurses application retrieve are those are set by zle, not the regular one because by the time they initialise, you're already back at the prompt. So at that point they see SUSP disabled. When they try to change the settings (which change other things than the SUSP setting), they're suspended with a SIGTTOU as they're not in foreground. Then when you fg it, zsh does restore the tty settings to the regular one, before sending a SIGCONT to the application, but then the application just resume their tcsetattr() which apply their changes on top of the initial settings, so they're reapplying the disabling of SUSP. If I run: stty -a < /dev/pts/1 (where /dev/pts/1 in my case is the tty htop is connected to and has been resumed) I see: intr = ^C; quit = <undef>; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = ^R; werase = ^W; lnext = <undef>; discard = <undef>; min = 1; time = 0; So it's not that htop is immune to SIGTSTP or that htop is not properly in foreground, it's that on that terminal, there's no character that causes SIGTSTP to be sent. If I start htop as: htop & sleep 1 Then, when htop retrieves the initial settings, you won't be back at the prompt as sleep will still be running, and you'll find that you can still suspend htop after resuming it with ^Z. You'll get the same behaviour with tcsh which also disables SUSP at its own line editor, but not bash and other shells that use readline, nor the few other shells I've tested which means they can't bind ^Z in their own line editor. Some of them do disable some special settings. For instance bash disables LNEXT (usually ^V).
ctrl+z doesn't send htop to the background
1,301,568,488,000
I would like to know how much CPU / memory my current iptables rules consume. I have tried looking in ps and htop, but even with kernel threads displayed and did not see anything related to iptables. I am using the conntrack module with these module-specific settings: xt_recent.ip_pkt_list_tot=1 xt_recent.ip_list_tot=4096. I think 4096 is quite high. And then, in my iptables configuration, I am using two kinds of block lists: BLACKLIST and PORTSCAN. -A INPUT -i eth0 -p icmp -j ACCEPT -A INPUT -i eth0 -s 1.2.3.4/32 -j ACCEPT -A INPUT -i eth0 -m recent --rsource --name BLACKLIST --seconds 14400 --update -j DROP -A INPUT -i eth0 -p tcp -m tcp --dport 25 -j ACCEPT -A INPUT -i eth0 -m recent --rsource --name PORTSCAN --seconds 3600 --update -j DROP -A INPUT -i eth0 -p udp -m udp --dport 5060 -j ACCEPT -A INPUT -i eth0 -p tcp -m tcp --dport 5061 -j ACCEPT -A INPUT -i eth0 -p udp -m udp --dport 5062:5100 -j ACCEPT -A INPUT -i eth0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -i eth0 -m recent --rsource --name PORTSCAN --set -j DROP -A INPUT -i eth0 -j DROP -A INPUT -j DROP I am experiencing network problems on the server, where I suspect my iptables rules could play a role. For instance: My ssh sessions are being dropped quite often. Ping reports 0.2% packet loss when I am connecting on allowed ports, ie 5060 it takes noticeably longer when PORTSCAN has many items, as compared when it is empty What would be the best way to troubleshoot this issue? is there some optimization I could do to my iptables rules? How can I see how much of my CPU is being consumed by iptables ?
Linux Kernel's Process: Many Kernel's functions like Iptables are processed in the Kernel level as kworker tasks, they are visible on task managers like top. As mentioned on the comments, you can compute the CPU and memory usage by comparing the total ressource usage usage with and without loading the iptables rules. Note that ipset already consumes memory even if you do not use it in a rule. Kworker is a placeholder process for kernel worker threads, which perform most of the actual processing for the kernel, especially in cases where there are interrupts, timers, I/O, etc. These typically correspond to the vast majority of any allocated "system" time to running processes. It is not something that can be safely removed from the system in any way, and is completely unrelated to the desktop applications (except if these programs make system calls, which may require the kernel to do something). Also kworker means a Linux kernel process doing "work" (processing system calls). You can have several of them in your process list: kworker/0:1 is the one on your first CPU core, kworker/1:1 the one on your second etc.. All Kernel's processes are started as children of kthreadd process on the Kernel space. Parent process: The process ID of kthreadd is 2 and this kernel workers can be listed with: pstree 2 -l -p # or ps --ppid 2 -u # or ps --ppid 2 -o pid,user,%mem,command,time,etime,cpu,pcpu,nice,pcpu,vsz That last one can be used with a bash + cron script to watch changes... alternatively for a direct timed analysis, perf can be used (apt-get install linux-tools-common linux-tools-3.11.0-15-generic) # Record 10 seconds of backtraces on all your CPUs: sudo perf record -g -a sleep 10 # Analyse your recording: sudo perf report Navigate the call graph with ←, →, ↑, ↓ and Enter. Links: 1, 2, 3, 4, 5, 6.
How to monitor the performance of "iptables" kernel module?
1,401,220,913,000
I was running a pipe command with one section being the following: sort -t $'\t' -T . -k1,1g When I was monitoring htop I saw this instead: What is the reason behind this? Does this mean my command is wrong or is there something wrong with htop?
There’s nothing wrong with your command, htop replaces control characters with question marks: (((unsigned char)data_c[j]) >= 32 ? ((unsigned char)data_c[j]) : '?') (characters with values less than 32 are control characters).
Why does `htop` display `$'\t'` as `?` in `sort` command?
1,401,220,913,000
I could find a process named typora from htop but I cannot trace it from ps or pstree $ ps -a | grep -i typora 9696 ttys003 0:00.01 grep -i typora $ pstree | grep -i typora | |--- 09713 me grep -i typora |--= 00258 me /Applications/Typora.app/Contents/MacOS/Typora -psn_0_40970 How could I find it from command ps.
From the ps manual on macOS (my emphasis): -a Display information about other users' processes as well as your own. This will skip any processes which do not have a controlling terminal, unless the -x option is also specified. Applications that are running on macOS without a controlling terminal, such as windowed Finder applications, will not be listed by ps -a. To list these, use ps -ax. Or, you may may use the -A or -e option: -A Display information about other users' processes, including those without controlling terminals. -e Identical to -A. If you are looking for information about a process with a particular name, consider using pgrep instead: pgrep Typora (note that case matters, unless you use pgrep -i) To signal a process with a particular name, use pkill rather than trying to grep the output of ps. See the manuals for pgrep and pkill. Also, even though this was not part of your question, pstree has a -s option to show only the branches of the process tree that contains processes with a particular name.
ps -a fails to find a process which is running
1,401,220,913,000
I am aware of the -u option in htop, where I can show only processes of a given user, such as: htop -u root I am wondering whether there is a way to show processes of all user except root.
This is not possible, as of htop 0.8.3. Source: the source code. The best you can do is sort processes by user, root's processes will be conveniently lumped together.
htop: show processes of all users except root
1,401,220,913,000
Previously I was using htop on 32-bit Manjaro, and it worked fine, then I switched to 64-bit ArchLinux, when starting htop it shows a blank screen, and any key press does nothing. I've tried to add TERM=xterm-color htop, but it does the same. My current $TERM value is xterm-256color. I've tried extra/htop 1.0.2-2, aur/htop-svn 308-1 and also aur/htop-blueweb 1.0.2-1 all give me a blank screen, anything I should do to fix this? EDIT: additional info for ldd: output of ldd /usr/bin/htop linux-vdso.so.1 (0x00007fff5ba70000) libncursesw.so.5 => /usr/lib/libncursesw.so.5 (0x00007fecdc490000) libm.so.6 => /usr/lib/libm.so.6 (0x00007fecdc188000) libc.so.6 => /usr/lib/libc.so.6 (0x00007fecdbdd8000) /lib/ld-linux-x86-64.so.2 (0x00007fecdc6f8000) i've tried to reinstall these packages: core/glibc multilib/lib32-glibc core/ncurses but there are no luck EDIT2: found out using strace that there are some program that causes htop to hang, after restarting the computer, problem solved..
The problem is either with your display setup or htop itself. To eliminate that it's an issue with htop can you attempt to redirect its output to a file? $ htop > htop_dump.txt After running this then hit Ctrl+C. If there's content in the file, more htop_dump.txt, then the issue likely lies with your screen setup in your terminal/shell. If on the otherhand this file also shows nothing, then something is broken in your system's setup, either with a library that htop depends on, or htop the binary itself. You might also want to attempt to run an strace to see if there's a resource/configuration file that htop is pulling in that's hosing it's display. Something like this: $ strace -o htop_strace.log -s 2000 htop
htop gives blank screen
1,401,220,913,000
what causes processes with no name in htop? this is a fully up to date debian 8.6 system, running htop 1.0.3 as root, amd64. and unix.stackexchange.com seems to shrink the image to an unreadable size, i recommend opening the image url http://image.prntscr.com/image/5ef407a1f99a4c9692db179a3afb2516.png directly
htop displays the process's command line with spaces between the arguments. (The first argument, argument number 0, is conventionally the command name passed by the parent process.) A process may overwrite its command line arguments with a string of the same length or shorter. A few programs use this to convey information about the state of the program. Screen sets the first argument (command name) to uppercase in the background process that manages the sessions and leaves the usually lowercase command name in the front-end process that runs in a terminal that's attached to the session.. It's also possible to start a process with no command line arguments. It's very unusual: conventionally the first argument is the command name. But it's technically possible. While this could be a display bug, or the effect of a command name containing carriage returns, the most likely explanation is that this process (currently) has no arguments. You can check by asking the kernel directly: cat -A /proc/12727/cmdline; echo This displays the arguments with control characters replaced by a visual representation. The arguments are separated by ^@. You can find other information by exploring /proc/12727, for example /proc/12727/exe is a symbolic link to the executable that's running in this process and /proc/12727/fd shows what files the process has open. You can also display this information with lsof -p12727. ps l 12727 will show other information about this process, in particular its parent process ID (PPID). (You can also configure htop to show this information by activating the corresponding column in the settings.)
what causes htop processes with no name?
1,401,220,913,000
I'm observing a multi threaded process in htop in tree view. If I were to strip it just to the problematic part, it looks somewhat like this: CPU% bin/process 100 `- thread1 70 `- thread2 0 The process all together is using 100% and one of the threads is using 70%. Where do I place the other 30%?
thread1 and thread2 are child threads spawned by the main process but the main process can still do work. In your output of htop bin/process (and all child threads) are using 100% of cpu. 70% of the cpu is used by thread1 and 0% by thread2, the remaining (difference) is the main process that spawn/manages these child threads.
'htop' process and threads cpu usage?
1,401,220,913,000
I'm running this: $ htop --pid=3907,3940,3941,3947 and would like to make the CPU/Memory at the top only count those PIDs. Is this possible? Other questions Also, are there flags for: enter 'tree' mode on startup, or change columns displayed? I'm trying to do it in a script, I know there are interactive methods.
Q#1: make the CPU/Memory at the top only count those PIDs. Is this possible? Unfortunately no top and htop do not provide a mechanism for only showing the individualized load in the upper portion of their output. However the CPU/Memory resources are displayed per process as 2 of the columns of output for each PID. enter 'tree' mode on startup, or You can configure htop so that these are the defaults. If you toggle tree view so that it's enabled and then exit htop using q or F10 when you re-launch it the tree view should persist, it's now the default. change columns displayed? The same applies to the columns. Select the ones you want and they'll become the defaults as well. NOTE: htop maintains its setting in this config file: ~/.config/htop/htoprc. Example $ head ~/.config/htop/htoprc # Beware! This file is rewritten by htop when settings are changed in the interface. # The parser is also very primitive, and not human-friendly. fields=0 48 17 18 38 39 40 2 46 47 49 1 sort_key=46 sort_direction=1 hide_threads=0 hide_kernel_threads=1 hide_userland_threads=0 shadow_other_users=0 show_thread_names=0 ... You could manipulate this file, htop makes no provisions for loading alternate files, so you'd have to beware of changing the file. You could also maintain your own file on the side, and then link to it prior to launching htop.
Making htop summaries respect --pid
1,401,220,913,000
Now I am using htop to show the process of my server, but I face a problem that when the command is very long, I just see part of the command and I did not know the full information of the process, is it possible to make the htop show full of the command? if the command too long , just wrap the output.
I don’t think you can make htop wrap long commands in the process list, but you can select a single process and see its full command line, wrapped, by pressing w. You can also scroll right and left to see different parts of the display, with ← and →.
how to make the htop wrap command line
1,401,220,913,000
Is there a way to run htop but display only the graphs (I don't want to see the individual processes)? I saw this question which seems to suggest no - I'm wondering if that has changed.
You can get the same effect by asking to see only a non-existant process id, eg htop -p 99999999
htop summary only display
1,401,220,913,000
My workstation have 256 logic cores, and it seems htop can only display 4 cores usage in one row. So there are 64 rows to display cpu usage, thus I can't see any process information in htop. And I do need to observe CPU usage. So I wonder if there is a method to let htop display 8 cores or even 10 cores usage in one line?
htop version 3.0.0 and later allow the CPU metrics to be split into 16 columns. To set that up, press F2, then → until you reach the “Available meters” column, move down to “CPUs (1-8/16)”, press Enter, use the cursor keys to move the new entry to the desired position, and press Enter again; do the same with “CPUs (9-16/16)”. To remove the old meters (“CPUs (1&2/4)” and “CPUs (3&4/4)”), select them with the cursor keys and press Del. This version of htop is only available in Ubuntu 22.04 or later; in earlier versions, you’d be better off removing the CPU meters entirely, or using only the “CPU average” meter (which shows the average usage across all cores):
How to let htop display as much as possible cores in one row
1,401,220,913,000
I frequently use htop to kill certain processes. To find the process I usually execute "Search" via F3. However, the list of processes refreshes frequently, and in many occasions, before I could press F9 for kill, another process is already highlighted, and thus I end up killing the wrong process! If I'm unlucky enough I end up killing a core process and thus causing a system logout/restart. Is there any way I can kill a certain process in htop being certain that I won't accidentally end up killing a wrong one?
I don't use htop, but judging from the man page it looks like you could use the space bar to "tag" a process, then the F9/k kill function will apply only to that process. Space Tag or untag a process. Commands that can operate on multiple processes, like "kill", will then apply over the list of tagged processes, instead of the currently highlighted one. ... F9, k "Kill" process: sends a signal which is selected in a menu, to one or a group of processes. If processes were tagged, sends the signal to all tagged processes. If none is tagged, sends to the currently selected process.
Preventing the accidental killing of wrong process in htop
1,401,220,913,000
It is well known that OpenBSD disables hyper-threading by default. However, htop shows 16 CPUs: 8 online and 8 offline, which takes extra space on the screen and is not very informative. Moreover, sysctl also sees 16 logical CPUs. This doesn't make sense to me: with hyperthreading disabled, it's an 8-core 8-thread processor, so I should see 8 physical/logical CPUs. $ sysctl hw hw.machine=amd64 hw.model=AMD Ryzen 7 5800H with Radeon Graphics hw.ncpu=16 hw.byteorder=1234 hw.pagesize=4096 hw.disknames=sd0:6d1abdce154d2fc8 hw.diskcount=1 hw.sensors.cpu0.frequency0=3900000000.00 Hz hw.sensors.cpu2.frequency0=3900000000.00 Hz hw.sensors.cpu4.frequency0=3900000000.00 Hz hw.sensors.cpu6.frequency0=3900000000.00 Hz hw.sensors.cpu8.frequency0=3900000000.00 Hz hw.sensors.cpu10.frequency0=3900000000.00 Hz hw.sensors.cpu12.frequency0=3900000000.00 Hz hw.sensors.cpu14.frequency0=3900000000.00 Hz hw.sensors.ksmn0.temp0=83.12 degC (Tctl) hw.sensors.it0.temp0=83.00 degC hw.sensors.it0.temp1=49.00 degC hw.sensors.it0.temp2=200.00 degC hw.sensors.it0.fan0=0 RPM hw.sensors.it0.fan1=3835 RPM hw.sensors.it0.fan2=2986 RPM hw.sensors.it0.volt0=1.74 VDC (VCORE_A) hw.sensors.it0.volt1=1.62 VDC (VCORE_B) hw.sensors.it0.volt2=2.67 VDC (+3.3V) hw.sensors.it0.volt3=3.71 VDC (+5V) hw.sensors.it0.volt4=10.69 VDC (+12V) hw.sensors.it0.volt5=-3.24 VDC (-12V) hw.sensors.it0.volt6=0.57 VDC (-5V) hw.sensors.it0.volt7=3.68 VDC (+5VSB) hw.sensors.it0.volt8=2.16 VDC (VBAT) hw.cpuspeed=3200 hw.setperf=100 hw.vendor=AZW hw.product=SER hw.version=Default string hw.serialno=A58003LH80340 hw.uuid=00020003-0004-0005-0006-000700080009 hw.physmem=13840232448 hw.usermem=13840216064 hw.ncpufound=16 hw.allowpowerdown=1 hw.perfpolicy=manual hw.smt=0 hw.ncpuonline=8 hw.power=1 hw.ucomnames= How do I disable logical processors, so that each "CPU" is a physical processor?
Availability of hyperthreading is managed from BIOS/EFI. What OpenBSD do is to put offline the processor(s)/thread(s). So You should do it in BIOS/EFI by disabling hyperthreading option.
How to disable logical processors in OpenBSD?
1,401,220,913,000
I am on Ubuntu 18.04 (Kubuntu), running through Konsole. I have a node process I can see in htop if I F4 and search for node. I highlight it and use F9 to send it a signal (tried SIGINT, SIGQUIT, SIGTERM, SIGKILL), but nothing causes it to exit. This is not specific to node, as I can't SIGKILL other things (for example the Kate text editor). If I exit htop and simply type kill -SIGINT 6015 (PID taken from htop), the process exits properly. Why is this not working? I am guessing it has something to do with how the desktop version works, because on servers I have never had the issue of htop being unable to signal processes. Another thing that goes contrary to my expectations is if I run sudo htop I can only see about 4 processes under my user (3 related to kde and one (sd-pam)) whereas running it as myself shows me 100+ (including node and all the other apps I have going). I would expect that running as root I would see all processes for all users.
I have good news, and bad news. Kill works for htop installed with sudo apt install htop. Kill doesn't works for htop installed with sudo snap install htop. I believe snap's sandbox is blocking the signal. Also, the htop from snap list fewer processes than the htop from apt.
Htop signals seem not to be sent on (K)Ubuntu 18.04
1,401,220,913,000
I start two new tmux sessions, the session name is variably build from a timestamp. (the commands create a new, detached tmux session, which first changes the directory, lists the content and then opens bash, in order to keep the session open) tmux new -d -s tmux-s1-2014-12-04-16-12-12-103728 'cd /home/user/dir/ect/; ls; bash' tmux new -d -s tmux-s2-2014-12-04-16-12-12-103728 'cd /home/user/dir/ory/; ls; bash' Now if i us htop or ps aux to see if they are still running, I always just find one of them. (e.g. ps aux | grep tmux) user 13556 0.0 0.0 26288 1716 ? Ss 16:12 0:00 tmux new -d -s tmux-s1-2014-12-04-16-12-12-103728 cd /home/user/dir/ect/; ls; bash user 13686 0.0 0.0 8072 864 pts/1 S+ 16:14 0:00 grep tmux Yet when i use tmux list-sessions both are listed: tmux-s1-2014-12-04-16-12-12-103728: 1 windows (created Thu Dec 4 16:12:20 2014) [80x23] tmux-s2-2014-12-04-16-12-12-103728: 1 windows (created Thu Dec 4 16:12:20 2014) [80x23] edit: I've now tested a little further and from what I understand now, detached sessions are invisible to htop/ps.. because of reasons. The first established session will be visible, even if detached. I've created three sessions, all with bash and detached the first and second session. The third session is still attached. Here's the output of htop when filtering for tmux. PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 17382 user 20 0 26296 1808 1176 S 5.0 0.1 0:00.86 ├─ tmux new -s first_session 17641 user 20 0 17552 1164 908 S 0.0 0.0 0:00.00 │ │ └─ tmux attach -t third_session Whereas tmux list-sessions will still show all three: first_session: 1 windows (created Fri Dec 5 10:35:11 2014) [80x23] second_session: 1 windows (created Fri Dec 5 10:35:23 2014) [80x23] third_session: 1 windows (created Fri Dec 5 10:35:37 2014) [80x23] (attached) The question is still the same.. Why is htop or ps aux unable to list all detached and attached sessions?
Tmux by default will only run one server process per user, and this server process can have multiple sessions. A Tmux client and the server communicate via a Unix domain socket in the /tmp directory. The -L option can be used to specify a different socket; a new server is created for each socket. Source: http://hyperpolyglot.org/multiplexers The tmux sessions aren't displayed by ps or htop because they are not processes. As you've discovered, the single tmux server process hosting all of the sessions for your user does show up, along with any tmux client processes that may be attached to your session(s). What you will see in the process list are any shells and other child processes that you have invoked in panes and windows of your tmux sessions. Check out this partial output of pstree -ap from a Linux machine where I am running tmux: |-sshd,3406 | |-sshd,18196 | `-sshd,18201 | `-bash,18202 | `-tmux,18297 att |-tmux,10496 new-session -s main | |-bash,10497 | | `-ssh,10584 otherhost.mydomain.local | |-bash,17650 | `-bash,18303 | |-less,18390 | `-pstree,18389 -ap | `-bash,18487 | `-cat,18573 - this-is-in-another-session You can see my tmux server process (10496). The first session I created has 3 panes (all running bash). One is ssh'd to otherhost. Another is sitting at a prompt, and so has no children. And the third is displaying pstree output in less. You can also see my tmux client process (18297). Those 3 panes are in one session that is attached. I have another session with one pane running bash and the cat process you see. That is detached, but still a child of the single tmux server process.
Why is my second tmux session not shown in ps aux or htop but in tmux list-sessions it is?
1,401,220,913,000
I'm managing a few compute servers w/ roughly 20 users each. I'm using htop to view current resource usage, however it would be very helpful to have a log of a specific user's cumulative memory and cpu usage. Is there any way to view/log this via htop or bash?
You could use top -bn1 -U {user} to create a file which you can then do additional processing on to gain a cumulative usage. The argument -bn1 makes top run in a non-interactive mode, simply outputting once when finished. You can then pipe that output anywhere for additional processing. for example, top -bn1 -U {user} > user_log.txt for additional processing in another script, or you could do something like, top -bn1 -U {user} | awk {file_processing_script} >> user_log.txt file_processing_script in that case is an awk script that processes the data in whatever way you want. one idea could be awk 'NR>7{cpu += $9; mem += $10} END {printf "%.2f\t%.2f\n", cpu, mem}', which will simply output the total cpu and memory usage from a specific user at the moment it is run. Append several of these together, and you get a nice table showing cpu and memory usage from a user.
Cumulative resource usage
1,401,220,913,000
Earlier today I was ordering a yard sign for a local politician, via their website, through Firefox. Just now I was doing some work in R, and checking htop to make sure I wasn't going to make my computer choke. This caught my eye: What is that highlighted line about? The tab is the link that's long closed. Is this an example of the website tracking me somehow? Why would Firefox support this sort of behavior? While I doubt that Elissa Silverman will do anything nefarious with data on my browsing habits, I'm perhaps a bit paranoid about what others might do. Anyway, what is this and can I block it? Should I block it?
As per the comments, if you launch Firefox by clicking a link, the resulting process will be associated with that argument. In other words, Firefox was launched with the equivalent of typing something similar to the following on the command line. $ firefox http://visited.website.com This means that the process as reported by htop includes this full command. You can see similar full commands in your screenshot with cinnamon and rsession; both of these include arguments after the actual command. Then, if Firefox is still open after you close the tab, the process is still running. There is no new process created, so htop still shows these arguments. A analogous situation is if you open a text editor by specifying a particular document (e.g. vim doc.txt), then close the document in the editor. Again, htop will report the full command, even after the document has been closed.
Looking at htop, I see a process associated with a tab in firefox that isn't open. What gives?
1,401,220,913,000
I deployed a hack to add swap space to a VPS that otherwise didn't allow me to use swapon to create a file. Prior to adding and executing the script, I followed the steps outlined here. and summarized below: First I create the swap file: sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k Then sudo mkswap /swapfile. The next step would usually have been to do a sudo swapon /swapfile. However, the VPS I'm using doesn't jive with that, so I found this post. That claimed I could use the following script as a workaround. See below: #!/bin/bash SWAP="${1:-512}" NEW="$[SWAP*1024]"; TEMP="${NEW//?/ }"; OLD="${TEMP:1}0" umount /proc/meminfo 2> /dev/null sed "/^Swap\(Total\|Free\):/s,$OLD,$NEW," /proc/meminfo > /etc/fake_meminfo mount --bind /etc/fake_meminfo /proc/meminfo For more context, the process is described in detail in this answer. (It's mostly just spoon-feeding on running a bash script.) All seems to be fine, however when I look in htop (or in free -m for that matter); the memory usage remains at whatever value it was at when I executed the script and the used swap space remains at zero. This is regardless of whatever process I run on the server. My knowledge of what's going on in memory allocation is very limited (this is really my first time screwing around with it). Could anyone tell me if this makes sense, given the script I'm running, and why?
You have greatly misunderstood what that post means by "fake swap". There are some programs that for various reasons insist on a system having swap space enabled (cough Oracle cough). If it isn't, the program—or at least its installer—complains. Of course with the aforementioned database there are ways to tell it to continue anyway, but people often don't know them. The "fake swap" you found is a workaround. It's a way to lie to those programs, and pretend swap is enabled. The swap is a lie. There is no actual swap. But the program believes there is, so it doesn't complain. The workaround also lies to free, etc., and lies about all the other values in /proc/meminfo as well. (Honestly: if I found this in use on a system I was using—much less administering—I'd use terms much harsher than "workaround". Terms that'd not be suitable for polite conversation.) Tante's answer on the other question is probably correct: OpenVZ does not support swap on VMs. There is no alternative to swapon. It does a bunch of checks, but then calls the kernel's swapon syscall. If the syscall isn't supported, you're done. You can't do it. Sorry. Depending on the actual problem you're trying to solve, there are some other approaches that may work: If a particular process needs to work with a huge amount of data, mmap probably still works. Or use more space-efficient algorithms. Allocate (or ask/pay the provider) more memory to the VM. Possibly enable swap on the host. Switch to a different virtualization solution, or to running on bare metal. You could probably run User Mode Linux inside your OpenVZ container. Inside that UML instance, you can probably enable swap. I fully expect performance to be terrible.
Swap bash script pins htop's memory usage
1,401,220,913,000
I found that my "PCI Adapter" overheats when load is above 4.0 (having 4 cores). It does NOT overheat when the load is below 4.0 (but I had an overclocked memory that was causing trouble as I explain at the end), so my focus is on lowering the system load. What overheats is just the k10temp-pci-00c3 PCI Adapter (according to sensors). The mistake: I am trying to track applications that compose that value, and how much each did. From this question, I found atop, but reading its output, it is not clear what applications composed the system load... It is like a "simple" column showing SYSLOAD is missing. It seems I could use all that displayed information to calculate something that could show such column, but I just don't know how. The explanations I found about system load seems too generic (I can be wrong..), so I couldn't understand them enough to produce an algorithm; I think I should mix some data like cpu usage, io usage, mem usage and so get the sysload even if it is somewhat fuzzily guessed... Precise info on how system Load works: on this question there is a reference to a pdf explaining it. Load seems not exactly related to specific applications... Still need a workaround: Anyway I still would like to know how possible it is to make an application approach about system load, may be there is some way to prioritize the whole system utilization to some specific application, while all the others clogging it, even when they are NOT using much cpu (less than 3%), calm down? Tests on-going: I set all processes to nice -n 19, but the one window/process I am actively using; I saw improvement on the temperature graph with psensor (the graph is a lot less fuzzy); the temperature is holding longer, below the limit, now; all processes seems to be behaving as expected; the system load is still high but I saw it once go til 6.0 and the temperature was still fine; no sudden shutdowns since.. need more test tho... Finally the culprit was found: My memory was supposed to accept 2000MHz. Long ago I set it to work at 1600MHz, because the machine would not boot otherwise. Now I set it to automatic, what made it work at 1333MHz. The temperature k10temp-pci-00c3 that was overheating (reaching above 80c) now is consistent around 60c when I run heavy applications! Also the load average is around 3.5 to 4.0 without causing any hardware problems! The nice 19 on processes helped postpone the overheating indeed, but wasnt able to totally prevent it!
You're asking the wrong question: you've got an overheating system which should be solved by cooling the system. Playing games with process load is going to yield an unsatisfying hack. And since you've got hardware running at its thermal limits, you can fairly expect that problem to worsen. If you cannot remedy the hardware, see if you can slow the whole processor clock down. Yep, you'll get a slower computer but it is the only reliable way to reduce power consumption / heat dissipation.
Should I care for applications that increase the system Load in order to prevent overheating?
1,401,220,913,000
Above is htop running in a terminal emulator. In the command column, some of the processes have their full path, eg. /usr/bin/python3, and some of them have just the command name, eg. caja, xonsh. Why is there a difference? Is there anything special about these processes? I suspect, but I'm not sure, that this might be the first element of "args" (unclear what the true name of it is), the program name.
From the man page of htop: Command The full command line of the process (i.e. program name and arguments). So if you run htop you will see the command without the full path. And if you run /usr/bin/htop -C -u$USER you will see the full path with arguments.
In the command column of htop, sometimes the full path is displayed, and sometimes it isn't. Why?
1,401,220,913,000
when i do a ps -efT (where -T = Show threads, possibly with SPID column.), i see all the threads have the same PID, which is as expected. myroot 24958 24958 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24959 7942 0 20:20 pts/12 00:00:11 java -jar myapp.jar myroot 24958 24960 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24961 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24962 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24963 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24964 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar myroot 24958 24965 7942 0 20:20 pts/12 00:00:00 java -jar myapp.jar As it can be seen above, all the threads share/show the same PID 24958. Now When I do the same with top or htop, i am seeing differnt pid for each thread and this is bothering me. Is there a way to show the same PID for all the threads. Below is the curtailed output for top -H -p 24958 (I am using top with -p, so i could explain and show the problem) top - 21:42:44 up 9 days, 18:38, 0 users, load average: 0.00, 0.26, 0.82 Threads: 32 total, 0 running, 32 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.0 us, 0.1 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 12542.5 total, 10135.3 free, 826.8 used, 1580.4 buff/cache MiB Swap: 4096.0 total, 4096.0 free, 0.0 used. 11439.4 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 24958 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 java 24959 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:11.99 java 24960 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.43 GC Thread#0 24961 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 G1 Main Marker 24962 myroot 20 0 7036228 340720 21084 S 0.0 2.7 0:00.00 G1 Conc#0 --and few more threads. When i use top -H, i would not have any means to say which all threads belong to same Process unless I see same PID for all of them. Any guidence on how to get the same PID for all the threads when using top (or htop. As I have observed, htop too has the same issue). Given @user1686 answer to use TGID column. I am wondering what the PID for the thread is refering to.
With htop, you want the TGID column (add it through F2 > Columns). It is also available in top with the same name, but I don't know how to configure top. Linux "processes" are really just thread groups (or task groups), and the "PID" column in top/htop actually shows the thread ID (task ID). The same clone(2) system call is used to create both – check out the part about CLONE_THREAD.
top shows different pid for threads of same process. How to fix it?
1,401,220,913,000
Let's say I'm running a multicore process. How do I "nice" this via htop after submission?
My version of htop displays this as the help line: F1Help F2Setup F3Search F4Invert F5Tree F6SortBy F7Nice - F8Nice + F9Kill F10Quit So you would hit F7 to decrease the "nice value", and F8 to increase it (the former may require special privileges).
How does one "nice" a PID via htop after the process has begun?
1,401,220,913,000
I recently installed a copy of Ubuntu Server 14.04.2 LTS on a cluster. All appears to be working fine, but a large portion (around half) of our total available RAM is being used. I.e., when I run free I get the following output (the buffers/cache line being the relevant one): total used free shared buffers cached Mem: 251 215 36 0 2 70 -/+ buffers/cache: 141 110 Swap: 22 0 22 I checked the outputs of both ps and lsof to get the total memory usage per user, and nobody is using more than 1% of the RAM. I've read that Linux does not immediately free up memory used by exited processes, but is it feasible that it would continue using this much memory? If not, is there anything else that could be taking up all of this memory?
I figured out that a large portion of the memory usage was, in fact, attributable to inactive memory used by exited processes. The most accurate way to determine how much memory is available post-January 2014 is to look at MemAvailable in /proc/meminfo. You can also see the amount of inactive memory is this file.
Substantial portion of memory used is not accounted for by user processes
1,401,220,913,000
My node application spawns ffmpeg processes. In htop, there are a bunch of ffmpeg processes I would have expected to have ended but they are still shown in htop. The threads in green are the process that is currently active. The ones in white are shown using memory, and the time column is not incrementing. Are these processes using any resources and should I be looking into what's causing these processes to now close cleanly?
Yes, they're using resources, though its hard to say how much; could be a very small amount. First thing to check for is just with ps, see if their status is Z (zombie). Which would mean they've exited, but you're not calling wait/waitpid/etc. on them. (Probably not, as I think Node handles this for you). Otherwise, they've probably got some RAM, some number of file descriptors (likely in both ffmpeg and Node), and of course a process in use; you will run out of all of those if your app is long-running and keeps leaking them. I suppose worst would be if it still has that HTTP connection open; that will consume resources on dar.fm too. Tools like ps, lsof, and even strace can help check on what resources those ffmpegs are using. Whether you should fix it... is something you'll have to decide based on how much it costs in programmer time to fix vs. extra hardware/operations time to manage.
Are these threads in htop using any resources?
1,401,220,913,000
I have the following script: #!/bin/bash /usr/bin/echo q | /usr/bin/htop -C | /usr/bin/aha --line-fix | /usr/bin/html2text -width 999 | /usr/bin/grep -v "F1Help\|xml version=" > htop.txt It just captures the htop output. It works fine if I run the script via command line but then if I run it via crontab as root: 15 15 * * 1-5 /bin/bash /root/collect_system_stats.sh htop.txt will have just 1 byte and hexdump shows: 0000000 000a 0000001 What I have done wrong?
You should use grep with the --line-buffered flag, otherwise grep exits after the first match. I don't have a full qualified explanation for this, but that's what made my script work in a similar case. Found this answer to line-buffer for grep. Installing a cronjob as root user with htop can result in a error message: /usr/bin/htop -C Error opening terminal: unknown Setting TERM=xterm in the script can resolve this issue.
Running Script via Crontab With Different Result?
1,401,220,913,000
I have the following htop output: What are the green, blue, and yellow bars respectively in this memory output?
When in htop, press F1 for the color key as well as a lot of other information
How to interpret the colors in htop's memory bar? [duplicate]
1,644,156,183,000
I'm on a system with 48 threads and the view for usage is taking up 4/5 of the vertical screen space. Is there a way to toggle the CPU usage window to just view the active PIDs?
You can’t toggle the top part of the screen in its entirety, but you can customize it. Press S to open the setup screen, then the right arrow to move to the column with the CPU entry, and Del to remove it. Esc will return to the main view. Other variants are possible, for example the “CPU average” meter shows the average CPU use across all CPUs on a single line: Whichever setup you end up with will be stored in htop’s configuration file, so subsequent invocations will start as you left it.
Minimize htop thread window?
1,644,156,183,000
lscpu gives: Thread(s) per core: 2 Core(s) per socket: 32 When running an intensive 32-threads process, why does htop show almost 100% CPU activity on #1-32, but very little activity on #33-64? Why aren't the process's 32 threads distributed evenly among CPUs #1-64?
In Linux there is a scheduler. Some systems will push work to faster/cooler/more-efficient cores but the default behavior is an ordered stack. The software you are running needs to take advantage of multiple cores for any benefit to be had, so it may be that your workload can only be split into 32 threads by your choice of software (or configuration).
Distribution of threads among CPUs?
1,644,156,183,000
I have a binary that I will be running multiple times in parallel, each instance executed with different input from the command line. I wanted htop to list only these processes so that I can compare the usage of memory based on the cli inputs. I tried [htop -p ] but this lists only one process even if I give muliple process ids as the input. Is there any way to get the output with input being multiple process IDs or with the part of the process name. Example as I hope to see in htop: PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 356 root 20 0 52952 7980 6632 S 0.0 0.8 0:00.00 ./test 1 357 root 20 0 2356 416 352 S 0.0 0.8 0:00.00 ./test 2 358 root 20 0 2356 332 268 S 0.0 0.8 0:00.00 ./test 3 Many thanks!
From man htop: F4, \ Incremental process filtering: type in part of a process command line and only processes whose names match will be shown. To cancel filtering, enter the Filter option again and press Esc. So, once you start htop, type \test and press Enter to filter in only commands containing test.
htop - See/Filter all the instances of a binary
1,644,156,183,000
I am a big fan of htop and would like to know if it is possible to turn it into a widget? I currently use Fedora 23 with Gnome 3.18.5. Currently I just open a terminal, resize it so show only the resource bars an top info, select always on top, Always on visible workspace and hide the menu bar. Is there any way to create a persistent terminal with htop that would appear when I login? If not, any alternative light weight resource monitor you suggest that could be used as a desktop widget?
Yes, Conky lua can be a better option. for you to get a desktop widget. But you need to modify it with htop. conky uses top.
Turn htop into widget
1,644,156,183,000
You can list the process ID of each widow with this command: wmctrl -lp Does there exist a command that shows the running command of each window (kind of like htop has a column for "Command")? If not, how could you combine commands to ultimately achieve this?
This will replace the pid in wmctrl -lp’s output with the corresponding command, if one is found: wmctrl -lp | awk '{ pid=$3; cmd="ps -o comm= " pid; while ((cmd | getline command) > 0) { sub(" " pid " ", " " command " ") }; close(cmd) } 1' This obviously won’t work for windows displaying remote processes; it also will give strange results for windows corresponding to sandboxed processes in some cases (e.g. Flatpak). The AWK script reads each line, extracts the pid, and runs ps -o comm= to determine the corresponding command; if one is found, it replaces the corresponding pid string with the command.
List Running Commands of All Windows
1,644,156,183,000
I've applied CPUAffinity to certain systemd services. I've checked Cpus_allowed_list from /proc/PID/status, and it works fine. Now I want to find out which process is using CPU 0 or CPU 1, how can I do that? the top or htop command does not seem to support such thing.
perf top -C 0,1 would give you insight into what is using how much time on the 0. and 1. cores. Attach --sort comm if you don't care about individual functions, but only about process names occupying the CPU. Run it as root to get insight into kernel usage as well. If you run it as unprivileged user, you will have to do sudo sysctl -w kernel.perf_event_paranoid=-1 to allow normal users to sniff around what the CPU does at any given time.
Find out which process is using CPU 0
1,644,156,183,000
I usually monitor my server resource usage. I am using htop for monitoring. When running htop the memory usage is 1.3G, which is fine for me. But I tried to view the memory used by each process. For this, I am using ps command. To view the memory used by MySQL, I am runing ps aux | grep mysqld. It prints these lines: root 13908 0.0 0.0 112660 972 pts/0 S+ 11:12 0:00 grep --color=auto mysql mysql 17984 2.6 3.1 2845500 387676 ? Ssl 2017 2974:34 /usr/sbin/mysqld So, it seems that MySQL uses 2845500 of memory, which means around 2.7G of memory, which is much higher than (1.3G) the full system memory usage showed by htop. Is that the number shown by ps, a number of bytes, instead of kilobytes? PS: I am using CentOS 7, 64 bit version.
2845500 is the amount of memory allocated by the process, not the amount it’s using. The latter is given by the next column: 387676. Both values are measured in kilobytes.
`ps` showing much higher ram usage than `htop`
1,644,156,183,000
From the author of htops answer https://stackoverflow.com/questions/41224738/how-to-calculate-system-memory-usage-from-proc-meminfo-like-htop/41251290#41251290 I got to know that the total memory in htop is calculated from /proc/meminfo. I think I could crosscheck this in code as well and it checks out. However compared to memory bar in htop. I see a major difference in the memory values shown in /proc/meminfo. In my /proc/meminfo the memory consumption reads MemTotal: 4144807288 kB MemFree: 3513532764 kB MemAvailable: 3936769368 kB Buffers: 1119392 kB So the Total used memory , which I think represented by the memory bar should be MemTotal-MemFree in GBs which should be (4144807288-3513532764)/1024^2=602Gb as far as I understand. However for me this value shows almost 180Gb. Could anyone explain how the values in /proc/meminfo and one in htop would become different.
My guess why the values differ is the following: htop "180G" value does not include system buffers and other memory used by operating system, while /proc/meminfo reports it as allocated Digging into https://github.com/htop-dev/htop/blob/541c17c975bc8a4f1f243e568006b0e26ae52c47/linux/LinuxMachine.c#L130 can help to understand how htop values are calculated
Discrepancy between values in htop and /proc/meminfo
1,644,156,183,000
I'm trying to measure the CPU% consumed by my app on a multi-core machine, meaning htop CPU% reports can go over 100%. I'm trying to get a simple read on CPU usage difference when I run my app in one configuration vs. another, but the change is likely less than 1% CPU and I'm seeing the following "107." for my process: I guess they hardcoded the CPU% column to only support 4 characters... is there a way to expand the width of this column so I can see fractional parts of three digit CPU% values? Ideally two digits of precision past the decimal.
I'm pretty sure that is going to be wasted precision*, in the sense that once you get to four significant digits the sampling would have to be accurate to more than 1 part in 1,000 and for five digits it would have to be more than one part in 10,000. It is very unlikely that the sampling is going to be accurate enough to detect that. And that's not even taking into account any inaccuracies because of other processes running on the same machine. Instead, what is usually done is running the code in a profiler, which can give accurate measurements of the performance of the code in isolation. * Like the joke about the museum employee telling people a dinosaur is 50,000,003 years old. Why so precise? Because it was dated as 50 million years old three years ago.
Can htop show more than 4 characters of CPU% data?
1,405,769,071,000
I've just installed CentOS7 as a virtual machine on my mac (osx10.9.3 + virtualbox) .Running ifconfig returns command not found. Also running sudo /sbin/ifconfig returns commmand not found. I am root. The output of echo $PATH is as below. /usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/robbert/.local/bin:/home/robbert/bin Is my path normal? If not, how can I change it? Also, I don't have an internet connection on virtual machine yet, maybe that's a factor.
TL/DR: ifconfig is now ip a. Try ip -s -c -h a. Your path looks OK, but does not include /sbin, which may be intended. You were probably looking for the command /sbin/ifconfig. If this file does not exist (try ls /sbin/ifconfig), the command may just be not installed. It is part of the package net-tools, which is not installed by default, because it's deprecated and superseded by the command ip from the package iproute2. The function of ifconfig without options is replaced by ip specifying the object address. ifconfig is equivalent to ip addr show and, because the object argument can be abbreviated and command defaults to show, also to ip a The output format is somewhat different: $ ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:10553 errors:0 dropped:0 overruns:0 frame:0 TX packets:10553 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:9258474 (9.2 MB) TX bytes:9258474 (9.2 MB) [ ... ] and $ ip address 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever [ ... ] Note the output is more terse: It does not show counts of packets handled in normal or other ways. For that, add the option -s (-stats, -statistics): $ ip -s addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever RX: bytes packets errors dropped overrun mcast 74423 703 0 0 0 0 TX: bytes packets errors dropped carrier collsns 74423 703 0 0 0 0 But what you actually want to see may be this: $ ip -stats -color -human addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever RX: bytes packets errors dropped overrun mcast 74.3k 700 0 0 0 0 TX: bytes packets errors dropped carrier collsns 74.3k 700 0 0 0 0 It shows counts with suffixes like 26.1M or 79.3k and colors some relevant terms and addresses. If you feel the command is too long, use the short options: This is equivalent: ip -s -c -h a
ifconfig command not found
1,405,769,071,000
At some point, in some teaching material (from Linux Foundation) on Linux that I came across, the following is mentioned: ip command is more versatile and more efficient than ifconfig because it uses netlink sockets rather than ioctl system calls. Can anyone elaborate a bit on this because I cannot understand what's going on under the hood? P.S. I am aware of this topic on those tools but it does not address this specific difference on how they operate
The ifconfig command on operating systems such as FreeBSD and OpenBSD was updated in line with the rest of the operating system. It nowadays can configure all sorts of network interface settings on those operating systems, and handle a range of network protocols. The BSDs provide ioctl() support for these things. This did not happen in the Linux world. There are, today, three ifconfig commands: ifconfig from GNU inetutilsjdebp % inetutils-ifconfig -l enp14s0 enp15s0 lo jdebp % inetutils-ifconfig lo lo Link encap:Local Loopback inet addr:127.0.0.1 Bcast:0.0.0.0 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:9087 errors:0 dropped:0 overruns:0 frame:0 TX packets:9087 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:51214341 TX bytes:51214341 jdebp % ifconfig from NET-3 net-tools jdebp % ifconfig -l ifconfig: option -l' not recognised. ifconfig:--help' gives usage information. jdebp % ifconfig lo lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> inet6 ::2 prefixlen 128 scopeid 0x80<compat,global> inet6 fe80:: prefixlen 10 scopeid 0x20<link> loop txqueuelen 1000 (Local Loopback) RX packets 9087 bytes 51214341 (48.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9087 bytes 51214341 (48.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 jdebp % ifconfig from (version 1.40 of) the nosh toolset jdebp % ifconfig -l enp14s0 enp15s0 lo jdebp % ifconfig lo lo link up loopback running link address 00:00:00:00:00:00 bdaddr 00:00:00:00:00:00 inet4 address 127.0.0.1 prefixlen 8 bdaddr 127.0.0.1 inet4 address 127.53.0.1 prefixlen 8 bdaddr 127.255.255.255 inet6 address ::2 scope 0 prefixlen 128 inet6 address fe80:: scope 1 prefixlen 10 inet6 address ::1 scope 0 prefixlen 128 jdebp % sudo ifconfig lo inet4 127.1.0.2 alias jdebp % sudo ifconfig lo inet6 ::3/128 alias jdebp % ifconfig lo lo link up loopback running link address 00:00:00:00:00:00 bdaddr 00:00:00:00:00:00 inet4 address 127.0.0.1 prefixlen 8 bdaddr 127.0.0.1 inet4 address 127.1.0.2 prefixlen 32 bdaddr 127.1.0.2 inet4 address 127.53.0.1 prefixlen 8 bdaddr 127.255.255.255 inet6 address ::3 scope 0 prefixlen 128 inet6 address ::2 scope 0 prefixlen 128 inet6 address fe80:: scope 1 prefixlen 10 inet6 address ::1 scope 0 prefixlen 128 jdebp % As you can see, the GNU inetutils and NET-3 net-tools ifconfigs have some marked deficiencies, with respect to IPv6, with respect to interfaces that have multiple addresses, and with respect to functionality like -l. The IPv6 problem is in part some missing code in the tools themselves. But in the main it is caused by the fact that Linux does not (as other operating systems do) provide IPv6 functionality through the ioctl() interface. It only lets programs see and manipulate IPv4 addresses through the networking ioctl()s. Linux instead provides this functionality through a different interface, send() and recv() on a special, and somewhat odd, address family of sockets, AF_NETLINK. The GNU and NET-3 ifconfigs could have been adjusted to use this new API. The argument against doing so was that it was not portable to other operating systems, but these programs were in practice already not portable anyway so that was not much of an argument. But they weren't adjusted, and remain as aforeshown to this day. (Some people worked on them at various points over the years, but the improvements, sad to say, never made it into the programs. For example: Bernd Eckenfels never accepted a patch that added some netlink API capability to NET-3 net-tools ifconfig, 4 years after the patch had been written.) Instead, some people completely reinvented the toolset as an ip command, which used the new Linux API, had a different syntax, and combined several other functions behind a fashionable command subcommand-style interface. I needed an ifconfig that had the command-line syntax and output style of the FreeBSD ifconfig (which neither the GNU nor the NET-3 ifconfig has, and which ip most certainly does not have). So I wrote one. As proof that one could write an ifconfig that uses the netlink API on Linux, it does. So the received wisdom about ifconfig, such as what you quote, is not really true any more. It is now untrue to say that "ifconfig does not use netlink.". The blanket that covered two does not cover three. It has always been untrue to say that "netlink is more efficient". For the tasks that one does with ifconfig, there isn't really much in it when it comes to efficiency between the netlink API and the ioctl() API. One makes pretty much the same number of API calls for any given task. Indeed, each API call is two system calls in the netlink case, as opposed to one in the ioctl() system. And arguably the netlink API has the disadvantage that on a heavily-used system it explicitly incorporates the possibility of the tool never receiving an acknowledgement message informing it of the result of the API call. It is, furthermore, untrue to say that ip is "more versatile" than the GNU and NET-3 ifconfigs because it uses netlink. It is more versatile because it does more tasks, doing things in one big program that one would do with separate programs other than ifconfig. It is not more versatile simply by dint of the API that it uses internally for performing those extra tasks. There's nothing inherent to the API about this. One could write an all-in-one tool that used the FreeBSD ioctl() API, for example, and equally well state that it is "more versatile" than the individual ifconfig, route, arp, and ndp commands. One could write route, arp, and ndp commands for Linux that used the netlink API, too. Further reading Jonathan de Boyne Pollard (2019). ifconfig. nosh Guide. Softwares. Eduardo Ferro (2009-04-16). ifconfig: reports wrong ip address / initial patch. Debian bug #359676.
ip vs ifconfig commands pros and cons
1,405,769,071,000
After substantial research I still haven't found an answer to this query, how can I modify the command 'ifconfig' to show my computer's MAC address?
The command that you want on MacOS, FreeBSD, and TrueOS is: ifconfig -a link OpenBSD's ifconfig doesn't have this. Further reading ifconfig. Mac OS 10 Manual Pages. Apple corporation. 2008. ifconfig. FreeBSD Manual Pages. 2015. https://unix.stackexchange.com/a/319354/5132
How to view your computer's MAC address using 'ifconfig'?
1,405,769,071,000
The ifconfig command dumps a lot of information at you, especially if you have a lot of interfaces, and you don't know where they come from. I've read through the "Ifconfig Command - Explained in Detail" tutorial page, which gives a great rundown on most of the information in ifconfig. But it doesn't contain all the information I want (and the article could also be outdated after its release in 2006). Using ip addr show eth0: 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:e2:80:18 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0 valid_lft forever preferred_lft forever I find it tough to parse some of the output. Under eth0: <…> describes… the interface capabilities? Uncertain where I can find the full set of options, uncertain what they're called, no idea what to google. What're the other options? state UP – I know there's also state DOWN and state RUNNING. These are all software constructs, right? Nothing is physically changing when I run ip link set dev eth0 down, right? So how does the kernel act differently when this state changes? Does this state change? group default – interface groups. What is the unique problem they solve? Under inet What does scope global mean? – How can a private IP have a global scope? What am I missing? What is the grammar of this command's output?
Addresses with global scope are global from the point of view of the host, i.e. they are not restricted to the host or the local link. The host does not care, and does nothing different, in the case the address falls within the ranges specified in RFC1819 (Address Allocation for Private Internets). The "private" addresses are private only by convention. The host does not care which router does NAT, and how many hops away from the host the address translation from private to public addresses is done. Besides, you can implement NAT with other addresses too.
How to understand (the output of) ifconfig or ip addr show [closed]
1,405,769,071,000
I'm trying to configure the network interface on embedded linux using ifconfig: ifconfig eth0 192.168.0.101 netmask 255.255.255.0 but I don't know how to add the default gateway as an ifconfig parameter, Any Ideas?
ifconfig is not the correct command to do that. You can use route like in route add default gw 192.168.0.254 for example. And if route is not present, but ip is, you can use it like this: ip route add default via 192.168.0.254 dev eth0, assuming that 192.168.0.254 is the ip of your gateway
How to set the Default gateway
1,405,769,071,000
I have a system with two NICs on it. This machine, and a few accompanying devices will be moved and attached to different LANs or sometimes it'll be using dial-up. eth0: - 10.x.x.x address space - no internet gateway - only a few devices eth1 (when used): - 172.16.x.x or 192.168.x.x or other address spaces - access to the gateway from LAN to internet ppp0 (when used): - internet access through dialup using KPPP I'm using ifconfig to bring interfaces up or down (other than with ppp0, which is handled by KPPP). If I bring up eth1 first, it gets an address from its DHCP and gets the gateway and that is added to routing so there's no trouble reaching the LAN and the internet. If I bring up eth0 first or second, it gets its address and sets the default gateway to within its address space (in the 10.x.x.x range). If I bring up eth0 first and eth1 second, the default gateway is still kept to within the 10.x.x.x range. So no matter what I do, eth0 will override eth1 and "claim" the gateway in the routing. Is there some way to either prevent eth0 from claiming the gateway, or to make sure eth1 (if brought up 2nd) uses its gateway? Or can I somehow prioritize a ranking of which interface's gateway should be used over the others? I basically want to make sure eth1's default address space gateway is used if it's active, and if not, then the ppp0's default gateway is used. I'd like to be able to prevent eth0 from ever having the default gateway.
The DHCP server configuration is wrong. It must not send a default gateway option when it can't provide routing to the rest of the world. If it does send that option then any client may assume that it can send packets for any off-link destination to the specified default gateway. So your box is right in using the default gateway from eth0 if it is told so by DHCP. The solution is to remove the bad option from your DHCP server.
Can I prevent a default route being added when bringing up an interface?
1,405,769,071,000
Can someone please elaborate on the difference between the various RX packets fields in ifconfig output? For example, let's say I run ifconfig and see the following: eth0 Link encap:Ethernet HWaddr AA:BB:CC:DD:EE:FF inet addr:1.1.1.1 Bcast:1.1.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:202723544 errors:0 dropped:4959 overruns:0 frame:37 TX packets:158354057 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4261083782 (3.9 GiB) TX bytes:1224803677 (1.1 GiB) Interrupt:83 Memory:f6bf0000-f6c00000 What is the difference between errors: dropped: overruns and frame: My guess at this point (based on some vague googling) is that frame: specifically pertains to CRC failures when the nic analyzes incoming frames and that errors: is a broader generic category. Then again... if that were the case, I would expect both of those fields to show numbers.
That information is poorly documented. I will tell you what I understand from my experience. frame counts only misaligned frames, it means frames with a length not divisible by 8. Because of that length is not a valid frame and it is simply discarded. Meanwhile errors counts CRC errors, too-short frames and too-long frames. overruns counts that times when there is FIFO overruns, caused by the rate at which the buffer gets full and the kernel isn't able to empty it. At last, dropped counts things like unintended VLAN tags or receiving IPv6 frames when the interface is not configured for IPv6.
What's the difference between "errors:" "dropped:" "overruns:" and "frame:" fields in ifconfig RX packets output?
1,405,769,071,000
I want to create an array in Bash which to contain all active network interfaces. I have managed to create a for loop printing them but when I try to create the array, it just contains the last lo interface but not the other. This is my code: #!/bin/bash for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF) do printf "$iface%s\n" declare -a array_test=["$iface"] done for i in "${array_test[@]}"; do echo "$i"; done And this is my output: eno1 eno2 eno3 lo [lo] Also, how can I exclude the lo localhost interface from the array?
Here is a solution, assign the list and then add item to it: #!/bin/bash array_test=() for iface in $(ifconfig | cut -d ' ' -f1| tr ':' '\n' | awk NF) do printf "$iface\n" array_test+=("$iface") done echo ${array_test[@]} If you want the output displayed one item per line: for i in "${array_test[@]}"; do echo "$i"; done To remove localhost from output: if [ "$iface" != "lo" ] then array_test+=("$iface") fi
Create an array with all network interfaces in bash
1,405,769,071,000
I'm trying to understand how network drivers work under Linux. This Q&A showed that the network device in Linux isn't represented by a device file. It states that network drivers work with sockets. For example, this references how to setup the network devices through ioctl calls. ioctl however needs a file descriptor, given that there are no device files for network drivers, the only file descriptor that can be passed is the one from the socket. This brings me to the point of the question. So far it seems like the network interface, which would be a software representation of a physical network card, is actually an inferior object to a socket. But what is a socket in this abstract sense, is it just another name for a device file that supports push notifications? I understand TCP sockets in term of connection points binded by a userspace app to a address:port pair on a network interface. I don't understand a socket as a prerequisite to set up a network interface. Can a network interface on Linux (like eth0 listed by ifconfig) exist without a socket? Does ifconfig or some network manager daemon keep a socket open to allow us set the network interface options?
Let's quickly review device files: In Linux, application programs communicate read and write operations to the kernel through file descriptors. That works great for files, and it turned out that the same API could be used for character devices that produce and consume streams of characters, and block devices that read and write blocks of fixed size at a random access address, just by pretending that these are also files. But a way was needed to configure those devices (set baud rates etc.), and for that, the ioctl call was invented. It just passes a data structure that's specific to the device and the kind of I/O control used to the kernel, and gets back the results in the same data structure, so it's a very generic extensible API and can be used for lots of things. Now, how do network operations fit in? A typical network server application wants to bind to some network address, listen on a certain port (e.g. 80 for HTTP, or 22 for ssh), and if a client connects, it wants to send data to and receive data from this client. And the dual operations for the client. It's not obvious how to fit this in with file operations (though it can be done, see Plan 9), that's why the UNIX designers invented a new API: sockets. You can find details in the section 2 man pages for socket, bind, listen, connect, send and recv. Note that while it is distinct from the file I/O API, the socket call nevertheless also returns a file descriptor. There are numerous tutorials on how to use sockets on the web, google a bit. So far this is all pure UNIX, nobody was talking about network interfaces at the time sockets were invented. And because this API is really old, it is defined for a variety of network protocols beyond the Internet protocol (look at the AF_* constants), though only a few of those are supported in Linux. But as computers started to get multiple network cards, some abstraction for this was needed. In Linux, that is the network interface (NI). It's not only used for a piece of hardware, but also for various tunnels, and user-application endpoints that serve as tunnels like OpenVPN, etc. As explained, the socket API isn't based on (special) files and is independent of the filesystem. In the same way, network interfaces don't show up in the file system, either. However, the NIs are made available in the /proc and /sys filesystem (as well as other networking tunables). A NI is simple a kernel abstraction of an endpoint where network packets enter and leave the kernel. Sockets, on the other hand, are used to communicate packets with applications. No socket needs to be involved with the processing of a packet. For example, when forwarding is enabled, a packet may enter on one NI and leave on another. In that sense, sockets and network interfaces are totally independent. But there had to be a way to configure NIs, just like you needed a way to configure block and character devices. And since sockets already returned a file descriptor, it was somewhat logical to just allow an ioctl on that file descriptor. That's the netdevice interface you linked. There are quite a few other abuses of system calls in a similar way, for example for packet filtering, packet capture etc. All of this has grown piece after piece, and is not particularly logical in many places. If it had be designed all at once, one could probably have made a more orthogonal API.
What is a generic socket and how does it relate to a network device?
1,405,769,071,000
I need to create a script that outputs the internal IP address, that is configured as the default Interface.
Here's another slightly terser method using procfs (assumes you're using Linux): default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route) ip addr show dev "$default_iface" | awk '$1 ~ /^inet/ { sub("/.*", "", $2); print $2 }' This returns both the IPv4 and (if available) the IPv6 address of the interface. You can change the test if you only want one or the other (look for inet for IPv4, and inet6 for IPv6). $ default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route) $ ip addr show dev "$default_iface" | awk '$1 ~ /^inet/ { sub("/.*", "", $2); print $2 }' 10.0.2.15 fe80::a00:27ff:fe45:b085 $ ip addr show dev "$default_iface" | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }' 10.0.2.15 $ ip addr show dev "$default_iface" | awk '$1 == "inet6" { sub("/.*", "", $2); print $2 }' fe80::a00:27ff:fe45:b085
How to display the IP address of the default Interface with Internet connection?
1,405,769,071,000
How to capture the first IP address that comes from ifconfig command? ifconfig -a enw178032: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 100.14.22.12 netmask 255.255.0.0 broadcast 100.14.255.255 inet6 fe80::250:56ff:fe9c:158a prefixlen 64 scopeid 0x20<link> ether 00:10:56:9c:65:8a txqueuelen 1000 (Ethernet) RX packets 26846250 bytes 12068811576 (11.2 GiB) RX errors 0 dropped 58671 overruns 0 frame 0 TX packets 3368855 bytes 1139160934 (1.0 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 Expected result: IP=100.14.22.12
It is better avoid using ifconfig for getting an IP address in a scriptas it is deprecated in some distributions (e.g. CentOS and others, do not install it by default anymore). In others systems, the output of ifconfig varies according to the release of the distribution (e.g. the output/spacing/fields of ifconfig differs from Debian 8 to Debian 9, for instance). For getting the IP address with ip, in a similar way you are asking: ip addr | awk ' !/127.0.0.1/ && /inet/ { gsub(/\/.*/, "", $2); print "IP="$2 } ' Or better yet: $ ip -o -4 address show | awk ' NR==2 { gsub(/\/.*/, "", $4); print $4 } ' 192.168.1.249 Or, as you ask "IP=" #!/bin/bash echo -n "IP=" ip -o -4 address show | awk ' NR==2 { gsub(/\/.*/, "", $4); print $4 } ' Adapting shamelessly the idea from @Roman $ ip -o -4 address show | awk ' NR==2 { gsub(/\/.*/, "", $4); print "IP="$4 } ' IP=192.168.1.249 Normal output: $ ip -o -4 address show 1: lo inet 127.0.0.1/8 scope host lo\ valid_lft forever preferred_lft forever 2: eth0 inet 192.168.1.249/24 brd 192.168.1.255 scope global eth0\ valid_lft forever preferred_lft forever From man ip: -o, -oneline output each record on a single line, replacing line feeds with the '\' character. This is convenient when you want to count records with wc(1) or to grep(1) the output. See one example of why ifconfig is not advised: BBB: `bbb-conf --check` showing IP addresses as `inet` - ifconfig woes For understanding why ifconfig is on the way out, see Difference between 'ifconfig' and 'ip' commands ifconfig is from net-tools, which hasn't been able to fully keep up with the Linux network stack for a long time. It also still uses ioctl for network configuration, which is an ugly and less powerful way of interacting with the kernel. Around 2005 a new mechanism for controlling the network stack was introduced - netlink sockets. To configure the network interface iproute2 makes use of that full-duplex netlink socket mechanism, while ifconfig relies on an ioctl system call.
How to capture the first IP address from a ifconfig command?
1,405,769,071,000
When I run ip to get the ip address, I'm getting $ ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 link/ether 6c:88:14:ba:cb:cc brd ff:ff:ff:ff:ff:ff None of that is an ipv4 address, however ifconfig does show it, $ sudo /sbin/ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 1102801 bytes 74417671 (70.9 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1102801 bytes 74417671 (70.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.7.7.57 netmask 255.255.252.0 broadcast 10.7.7.255 inet6 fe80::440:3794:6794:8b1b prefixlen 64 scopeid 0x20<link> inet6 2620:0:28a2:4010:2:2:8c75:f8a1 prefixlen 128 scopeid 0x0<global> ether 6c:88:14:ba:cb:cc txqueuelen 1000 (Ethernet) RX packets 32743430 bytes 48351612590 (45.0 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 14856403 bytes 1590947780 (1.4 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 How can I get the ipv4 information without falling to my deprecated (and trusty) ifconfig?
Apparently ip broke up the MAC address (now in the ip link (device) interface), and the network ip address. The command ip address is what shows the network addresses, 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 6c:88:14:ba:cb:cc brd ff:ff:ff:ff:ff:ff inet 10.7.7.57/22 brd 10.7.7.255 scope global dynamic noprefixroute wlp3s0 valid_lft 1203509sec preferred_lft 1203509sec inet6 2620:0:28a2:4010:2:2:8c75:f8a1/128 scope global dynamic noprefixroute valid_lft 1203512sec preferred_lft 598712sec inet6 fe80::440:3794:6794:8b1b/64 scope link noprefixroute valid_lft forever preferred_lft forever This can be seen in a more compact and user friendly (-brief) format with $ ip -4 -br addr show lo UNKNOWN 127.0.0.1/8 wlp3s0 UP 10.7.7.57/22 Or, you can see it one line (-o), $ ip -o address 1: lo inet 127.0.0.1/8 scope host lo\ valid_lft forever preferred_lft forever 1: lo inet6 ::1/128 scope host \ valid_lft forever preferred_lft forever 3: wlp3s0 inet 10.7.7.57/22 brd 10.7.7.255 scope global dynamic noprefixroute wlp3s0\ valid_lft 1202464sec preferred_lft 1202464sec 3: wlp3s0 inet6 2620:0:28a2:4010:2:2:8c75:f8a1/128 scope global dynamic noprefixroute \ valid_lft 1202466sec preferred_lft 597666sec 3: wlp3s0 inet6 fe80::440:3794:6794:8b1b/64 scope link noprefixroute \ valid_lft forever preferred_lft forever
How can I get the ipv4 address from `ip link` like I used to see with ifconfig?
1,405,769,071,000
I claim an IPv6 address using ifconfig in a script. This address is then immediately used to listen on a TCP port. When I write the script like this, it fails because the service is unable to listen: ifconfig igb0 inet6 2001:db8::10/64 add service my_service start #fails However, it succeeds when I do it like this: ifconfig igb0 inet6 2001:db8::10/64 add sleep 1 service my_service start I tried writing the output of ifconfig directly after running the add-operation. It appears that ifconfig reports the IP-address as being tentative, which apparently prevents a service from listening on it. Naturally, waiting exactly one second and hoping that the address has become available is not a very good way to handle this. How can I wait for a tentative address to become available, or make ifconfig return later so that the address is all set up?
An address can be in several states, tentative is one of them. Having ifconfig wait for an address to leave the state tentative is simply not in accord with the design. You may configure to use optimistic DAD as defined in RFC 4429. The purpose is to make an address available to applications even if the DAD is not yet completed. You may need to reconfigure the kernel to utilize this feature. Once the kernel is built to provide optimistic DAD, then you may certain sysctl-settings to enable it. From ip-sysctl.txt: /proc/sys/net/ipv6/* Variables: ... conf/interface/*: Change special settings per interface. The functional behaviour for certain settings is different depending on whether local forwarding is enabled or not. ... optimistic_dad - BOOLEAN Whether to perform Optimistic Duplicate Address Detection (RFC 4429). 0: disabled (default) 1: enabled use_optimistic - BOOLEAN If enabled, do not classify optimistic addresses as deprecated during source address selection. Preferred addresses will still be chosen before optimistic addresses, subject to other ranking in the source address selection algorithm. 0: disabled (default) 1: enabled That is, do something like sysctl -w net.ipv6.conf.enp2s6.optimistic_dad=1 sysctl -w net.ipv6.conf.enp2s6.use_optimistic=1 at boot time.
Let ifconfig wait for IPv6-address to not be tentative
1,405,769,071,000
CentOS 5.9 I'd like to reset the RX/TX counters in ifconfig output for an interface. My understanding is that these counters get reset during a reboot but I'd like to avoid rebooting. Is there another way I can reset that that is non-intrusive to data delivery?
This has already been answered by @SuB on Ask Ubuntu. I've adapted the answer for CentOS: Those counters are kept by the kernel, so your answer depends on how your network card driver is built. Two possible choices: As a kernel module Built into the kernel file itself In second case, you can not reset counters. In the first case, you can do it by unloading the module from the kernel and then loading it back again. If your NIC card uses the e1000 module, use the following commands: ifconfig eth0 down modprobe -r e1000 modprobe e1000 ifconfig eth0 up Use ethtool to find out your NIC module: ethtool -i eth0 After "driver" you see your module name: driver: e1000 version: 7.3.21-k8-NAPI firmware-version: ... Use yum to install ethtool as follows: yum install ethtool
How can I manually reset RX / TX counters in ifconfig output without impacting data delivery?
1,405,769,071,000
In Red Hat Enterprise Linux (RHEL) 8, if someone does ifconfig eth0 hw ether abcd12341234, all I know is ifconfig and ip -a, so then is there a way to reliably get the real MAC address of that eth0 interface and if so how? ... other than for example rebooting to a Linux live CD coming from a reliable source to be sure the MAC address of the interface hasn't been changed.
This answer is about Linux. ifconfig is obsolete and doesn't have access to a kernel API able to provide it this information. This information has been able to be retrieved for a long time with ethtool --show-permaddr. Example (redacted): # ethtool --show-permaddr eth0 Permanent address: 10:1f:74:32:10:fe Some board/firmware/driver combination might not have a permanent address and the result could be like this: # ethtool --show-permaddr eth0 Permanent address: not set A recent enough ip link/kernel will provide (possibly through an other API) the permanent address whenever the current address differs from an existing permanent address if it is set. For example (redacted): # ip link set dev eth0 address 12:34:56:78:9a:bc $ ip link show dev eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 12:34:56:78:9a:bc brd ff:ff:ff:ff:ff:ff permaddr 10:1f:74:32:10:fe Here permaddr 10:1f:74:32:10:fe represents the original MAC address. It's provided only when the current MAC address differs from the permanent MAC address. Such change could also have happened temporarily for example when an interface is set as a bond slave and (depending on its mode) inherits the bond's MAC address. To retrieve it programmatically, even when it was not changed, better use the JSON output and jq, for example like this: ip -json link show dev eth0 | jq -r '.[] | .permaddr // .address' which retrieves the permanent MAC address or if not provided the MAC address (which means it's the unchanged permanent MAC address... unless there is none, in which case it's the current). If this matters, one must first be sure there is a permanent address, because contrary to ethtool it doesn't appear to allow to know there is no known permanent address set for the board/firmware/driver combination.
How to find unspoofed MAC address of NIC
1,405,769,071,000
I'm using Debian 8. How do I get my external IP address from a command line? I thought the below command would do the job ... myuser@myserver:~ $ /sbin/ifconfig $1 | grep "inet\|inet6" | awk -F' ' '{print $2}' | awk '{print $1}' addr:192.168.0.114 addr: addr:127.0.0.1 addr: but as you can see, it is only revealing the IP address of the machine in the LAN. I'm interested in knowing its IP for the whole world.
You mean whatever routable IP your dsl/cable modem/etc. router has? You need to either query that device OR ask an outside server what IP it sees when you connect to it. The easiest way of doing that is to search google for "what is my ip" and like the calculation searches, it will tell you in the first search result. If you want to do it from the command line, you'll need to check the output of some script out there that will echo out the information. The dynamic dns service dyndns.org has one that you can use - try this command wget http://checkip.dyndns.org -O - You should get something like HTTP request sent, awaiting response... 200 OK Length: 105 [text/html] Saving to: ‘STDOUT’ - 0%[ ] 0 --.-KB/s <html><head><title>Current IP Check</title></head><body>Current IP Address: 192.168.1.199</body></html> - 100%[===================>] 105 --.-KB/s in 0s 2017-09-20 14:16:00 (15.4 MB/s) - written to stdout [105/105] I've changed the IP in mine to a generic non-routable and bolded it for you. If you want just the IP, you'll need to parse it out of there - quick and dirty, but it works for me. And I'm 100% sure there is a better safer way of doing it... wget http://checkip.dyndns.org -O - | grep IP | cut -f 2- -d : | cut -f 1 -d \< Which will give you just 192.168.1.199
How do I get my IP address from the command line? [duplicate]
1,405,769,071,000
I have a MacBook Pro 15" 2018 (Touch Bar). I see it has a lot of network interfaces. I would like to know what they are/what they do. I did some research but I couldn't really figure out all of them, here are their SCNetworkInterfaceInfo.UserDefinedName with information I was able to find from this answer: ap1: ? awdl0: ? llw0: ? utun0: ? utun1: ? lo0: loopback (localhost) gif0: Software Network Interface stf0: 6to4 tunnel interface en0: physical wireless en1: Thunderbolt 1 en2: Thunderbolt 2 en3: Thunderbolt 3 en4: Thunderbolt 4 en5: iBridge / Apple T2 Controller en6: Bluetooth PAN en8: iPhone USB en9: VM network interface en10: iPad bridge0: Thunderbolt Bridge The search engine for the Unix & Linux StackExchange is offline as of the time I'm posting this question. Thanks in advance. lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280 stf0: flags=0<> mtu 1280 en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 status: active ap1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500 status: inactive en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 status: active en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 status: inactive en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 status: inactive en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 status: inactive en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 status: inactive bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 options=63<RXCSUM,TXCSUM,TSO4,TSO6> Configuration: id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0 maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200 root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0 ipfilter disabled flags 0x0 member: en1 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 9 priority 0 path cost 0 member: en2 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 10 priority 0 path cost 0 member: en3 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 7 priority 0 path cost 0 member: en4 flags=3<LEARNING,DISCOVER> ifmaxaddr 0 port 8 priority 0 path cost 0 nd6 options=201<PERFORMNUD,DAD> status: inactive awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500 status: active llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 status: active utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380 utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000 en10: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 status: active en8: flags=8822<BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500 status: inactive
For the ones that you don't have: ap1: Access Point. This is used if you are using your MacBook as a wireless host where you are sharing its connection. awdl0: Apple Wireless Direct Link. WIFI p2p connection for things like AirDrop, Airplay, etc. Also used for Bluetooth. llw0: Low-latency WLAN Interface. Used by the Skywalk system. utun0: Tunneling interface. Used for VPN connections to tunnel traffic or for software like Back To My Mack. utun1: Same as utun01
What are these ifconfig interfaces on macOS
1,405,769,071,000
I create a loopback interface using: #ifconfig lo1 create The problem is when I reboot the machine I loose my configuration. I tried to modify the /etc/rc.conf file but I didn't figure the right way to do it. Can any one tell me how can I do that? Thanks!
You can add in your /etc/rc.conf: cloned_interfaces="lo1" ifconfig_lo1="inet a.b.c.d/netmask" where a.b.c.d is the ip address.
Create a loopback interface and make it permanent (FreeBSD)
1,405,769,071,000
I want to count the number of entries starting with the string "tun" that I get as output of the command ifconfig. For example, if this is my output, I want to count to be 2. I tried to play around with grep, but it is still not solved. docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.0.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:16:73:86:ba txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s31f6: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 00:00:00:00:00:00 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 16 memory 0xa1300000-a1320000 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 :: prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 905 bytes 80293 (80.2 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 905 bytes 80293 (80.2 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500 inet 00.00.00.00 netmask 255.255.255.255 destination 192.168.105.77 inet6 :: prefixlen 64 scopeid 0x20<link> unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC) RX packets 438 bytes 52174 (52.1 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 457 bytes 33911 (33.9 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 tun1: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500 inet 0.0.0.0 netmask 255.255.255.255 destination 192.168.104.61 inet6 :: prefixlen 64 scopeid 0x20<link> unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 10 bytes 584 (584.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
It is possible using either a combination of grep and wc, or using awk First approach, using grep: ifconfig | grep "^tun" | wc -l This will pipe the output of ifconfig through grep, match all lines starting with the string tun (this is accomplished using the "anchor" indicator ^), and then use wc to count the lines which grep output as matched. As pointed out by @schaiba, it is even possible without resorting to wc by virtue of grep's -c option, which will count all matched lines by itself: ifconfig | grep -c "^tun" Second approach, using awk: ifconfig | awk 'BEGIN {tuns=0}; /^tun/ {tuns++}; END {print tuns}' This will pipe the output to awk. The awk program, enclosed between single quotes ' ... ', does the following: at the beginning (BEGIN { ... }), initialize an internal varible tuns, which we will use for book-keeping, as 0 in the main loop, for every line encountered that starts with the string tun (indicated by the regular expression /^tun/), increase the counter tuns after the input is finished, (END { ... }), output the resulting value of tuns
Count network interfaces in Bash
1,405,769,071,000
I have linux redhat machine version 6.5 I reboot machine and work as single user mode , then I set the network on eth0 with default gw address /etc/sysconfig/network-script/ifcfg-eth0 but from some reason dg address not appears from netstat -rn after service network restart my question - can we set default gw address and start network when we in single user mode ?
Single-user mode by definition does not implement networking at startup. To put it in sysV runlevel terms, you want runlevel 2 (local multi-user with networking). You can switch to this with telinit 2. The standard runlevel definitions are: 0 - Halt the system 1 - Single-user mode 2 - Multi-user with networking, but no network services (e. g. NFS) 3 - Multi-user with networking and services 4 - Undefined 5 - Multi-user with networking, services, and GUI (e. g. Xorg) 6 - Reboot the system.
linux + single user mode and set network
1,405,769,071,000
When I run the command ifconfig in the terminal, I get three results: lo, virbr0, wlo1. What is wlo1? Is it useful?
wlo1 is a wireless network interface (NIC). You can use the command iwlist scan to scan the wireless NICs for available WiFi SSIDs. Examples iw is the preferred tool when querying WiFi devices. You can also use NetworkManager's CLI tool, nmcli, or if you're on an older version of Linux, use iwlist. iw $ iw dev wlan0 scan BSS 15:cd:10:e4:26:39(on wlan0) TSF: 0 usec (0d, 00:00:00) freq: 2412 beacon interval: 100 TUs capability: ESS Privacy ShortPreamble ShortSlotTime RadioMeasure (0x1431) signal: -8.00 dBm last seen: 0 ms ago SSID: bill_fi_the_science_wi Supported rates: 1.0* 2.0* 5.5* 11.0* 18.0 24.0 36.0 54.0 DS Parameter set: channel 1 TIM: DTIM Count 0 DTIM Period 1 Bitmap Control 0x0 Bitmap[0] 0x0 ERP: <no flags> ERP D4.0: <no flags> RSN: * Version: 1 * Group cipher: CCMP * Pairwise ciphers: CCMP * Authentication suites: PSK ... iwlist (older cli) $ iwlist scan enp2s0 Interface doesn't support scanning. lo Interface doesn't support scanning. enxfcde56ff0106 Interface doesn't support scanning. wlo1 Scan completed : Cell 01 - Address: C8:D7:79:50:D4:03 Channel:1 Frequency:2.412 GHz (Channel 1) Quality=62/70 Signal level=-48 dBm Encryption key:on ESSID:"hermes" Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s 9 Mb/s; 12 Mb/s; 18 Mb/s Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s Mode:Master Extra:tsf=000000150d484187 Extra: Last beacon: 7724ms ago IE: Unknown: 00066865726D6573 IE: Unknown: 010882848B960C121824 IE: Unknown: 030101 IE: Unknown: 050400010000 IE: Unknown: 2A0104 IE: Unknown: 32043048606C IE: Unknown: 2D1A2C101FFFFF000000000000000000000000000000000000000000 IE: Unknown: 3D1601000000000000000000000000000000000000000000 IE: IEEE 802.11i/WPA2 Version 1 Group Cipher : TKIP Pairwise Ciphers (2) : TKIP CCMP Authentication Suites (1) : PSK IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00 IE: Unknown: DD1E00904C332C101FFFFF000000000000000000000000000000000000000000 IE: Unknown: DD1A00904C3401000000000000000000000000000000000000000000 IE: Unknown: DD0600E04C020160 References Troubleshooting wifi connection on an HP Laptop on Ubuntu Renaming my wlan network interface iw man page
What is 'wlo1' ?
1,405,769,071,000
I am having some trouble with the apparently easy task of creating a virtual network adapter on a physical network card in my Linux system (custom distribution, Debian-based). If I run ifconfig eth0:1 10.50.55.130 netmask 255.255.255.0 everything goes just fine: the virtual NIC is silently added and correctly shown by ifconfig. I want the definition for this virtual NIC to appear in /etc/network/interfaces though. I have added the following stanza. # virtual NIC # auto eth0:1 iface eth0:1 inet static address 10.50.55.130 netmask 255.255.255.0 First line commented out because as of now I am not interested in having the system bring the network interface up automatically. Everything seems fine. If I run ifup eth0:1, though, I get SIOCSIFFLAGS: Cannot assign requested address. What I really can't wrap my head around is that the virtual NIC is actually created. Here's the output from ifconfig. can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00- 00-00-00 UP RUNNING NOARP MTU:16 Metric:1 RX packets:1206446 errors:0 dropped:0 overruns:0 frame:0 TX packets:193280 errors:0 dropped:12 overruns:0 carrier:12 collisions:0 txqueuelen:10 RX bytes:7645126 (7.2 MiB) TX bytes:1393003 (1.3 MiB) Interrupt:68 can1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 UP RUNNING NOARP MTU:16 Metric:1 RX packets:299171 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:2393368 (2.2 MiB) TX bytes:0 (0.0 B) Interrupt:71 eth0 Link encap:Ethernet HWaddr 98:5d:ad:c2:30:30 inet addr:10.90.100.43 Bcast:0.0.0.0 Mask:255.255.248.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1560275 errors:0 dropped:1 overruns:0 frame:0 TX packets:790 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:96964255 (92.4 MiB) TX bytes:176882 (172.7 KiB) Interrupt:56 eth0:1 Link encap:Ethernet HWaddr 98:5d:ad:c2:30:30 inet addr:10.50.55.130 Bcast:10.50.55.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:56 eth1 Link encap:Ethernet HWaddr 98:5d:ad:c2:30:32 inet addr:169.254.8.141 Bcast:169.254.255.255 Mask:255.255.0.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:140932 errors:0 dropped:0 overruns:0 frame:0 TX packets:140932 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8522761 (8.1 MiB) TX bytes:8522761 (8.1 MiB) Why am I getting this error? Or... Why does the NIC get created? I'll add that if I invoke ifup -f eth0:1 (with the force option) no error messages are shown AND the virtual network adapter is brought up just fine.
ifconfig is considered obsolete these days. Try to use ip tool instead. All recent distributions should support it, it's part of iproute tool set. If you just want additional IP address on the interface, use following command: ip addr add 10.50.55.130/24 dev eth0 And I agree with Johan Myréen's comment bellow your question.
Virtual NIC: "SIOCSIFFLAGS: Cannot assign requested address" but gets created
1,405,769,071,000
I used Ethernet over USB for some years to connect from my Debian 8 workstation to a Linux device with g_multi running. Today it stopped working, although (everybody says that) "I didn't touch anything". What I know: The device is okay (Ethernet over usb is fine on another machine) USB port and cable is okay (mass storage from the device is still mounted) lsmod lists usbnet, rndis_host, rndis_wlan and cdc_ether, as expected /etc/network/interfaces still reads: ` allow-hotplug usb0 auto usb0 iface usb0 inet static address 192.168.42.10 netmask 255.255.255.0 ifup usb0 fails with - Cannot find device "usb0" Failed to bring up usb0. ifconfig usb0 doesn't find the device dmesg|grep usb0 gives me rndis_host 4-1.1:1.0 usb0: register 'rndis_host' at usb-0000:00:1d.0-1.1, RNDIS device, ee:00:... I tried a reboot, which didn't help, but produced another strange effect: eth0 didn't start via the network manager. I had to put it in /etc/network/interfaces to get my network up. Related or a different phenomenon? Any hints on how to narrow where the problem is?
Solved: It's been an predictable network interface name issue, renaming usb0 to something weird. Why this happend all of a sudden after years? I don't know. Maybe for the first time the USB connection was aready established while booting, so the system decided to behave like a multi-netinterface machine? Anyhow, the problem is solved.
Ethernet over USB stopped working: Cannot find device USB0
1,405,769,071,000
Open-Vswitch creates virtual interfaces, they all have this pattern: s[digit]-eth[digit] For example: s1-eth1, s1-eth2, s12-eth3, s2-eth3 ... I want to show information of -for example- all interfaces starting with s1 (in our example, it must give s1-eth1 and s1-eth2). I tried this command, but it shows only the first line of information: I am more interested about information like RX packets, TX packets, erros, HWaddr.. like this:
For your current ifconfig output: ifconfig | grep -A7 --no-group-separator '^s1-eth'
How to show only interfaces starting with a certain pattern
1,405,769,071,000
We have some Red Hat servers, cluster servers for a mabri cluster. A few questions: Which Linux command prints the current MTU value? We have not yet configured MTU in the ifcfg file) What is the default MTU value (assuming that we installed the Red Hat machine from an ISO image) In which cases do we need to use high MTU values and what is the maximum value? What is the formula to calculate the MTU?
In my opinion the question should not be "How to know ...if"; it is more suitable asking "When should I setup Jumbo frames". As per your questions about MTU/Jumbo frames: To see your MTU, either ifconfig or ip do: $ ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.249 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:0c:29:40:68:ee txqueuelen 1000 (Ethernet) RX packets 50182 bytes 22054712 (21.0 MiB) RX errors 0 dropped 3 overruns 0 frame 0 TX packets 6674 bytes 838613 (818.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 Or with ip: $ ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:40:68:ee brd ff:ff:ff:ff:ff:ff inet 192.168.1.249/24 brd 192.168.1.255 scope global eth0 valid_lft forever preferred_lft forever Or more simply: $ ip link show eth0 | grep mtu 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 Normally in IPv4, the default is MTU being 1500 (bytes). 3 and 4) Usually the default MTU is fine. Rarely you have to change it for lower, temporarily, when dealing with communications problems, when firewalls are blocking ICMP packets which do not allow MTU to be negotiated. The other situation you may wish to change MTU is for defining JUMBO frames. However, you do not benefit alway of using JUMBO frames, only in specific cases like a dedicated VLAN of file servers or maybe DB servers, and on top of that, in a VLAN with JUMBO frames ALL the machines have to be configured for JUMBO frames; the switches also have to support JUMBO frames. You surely do not want to use JUMBO frames for Internet facing systems, like web servers or DNS servers. For setting in run time an interface for JUMBO frames: ip link set eth0 mtu 9000 Or in /etc/network/interfaces (in Debian) for making it permanent: auto eth0 iface eth0 inet static address 192.168.1.100 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 mtu 9000 For RH based systems: Do vi /etc/sysconfig/network-scripts/ifcfg-eth0 and add: MTU="9000"
How to know if my servers should use jumbo frames (MTU)