Slow start of Midnight Commander

Is there any way to prevent mc from taking 10-30 seconds to open?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

mc/subshell integration is a frequent culprit; to verify, try:

alias mc="mc --nosubshell"

Method 2

Actually editing /etc/hosts solved the problem for me.

My mc took 10 seconds to start due to the fact that during startup mc tries to resolve the local hostname to an IP address.

I added to /etc/hosts the following line (my hostname is FOO)

127.0.0.2 FOO.domain FOO

That instantly solved the problem.

Method 3

It works for me now. I am using

GNU Midnight Commander 4.8.21

strace wait on long time

connect(3, {sa_family=AF_INET, sin_port=htons(6011),
  sin_addr=inet_addr("x.x.x.x")}, 16) = ? ERESTARTSYS
  (To be restarted if SA_RESTART is set)'

I tried this:

# hostname

use this for /etc/hosts:

nameofhost=hostname

add this $nameofhost to the /etc/hosts on line starting with

127.0.0.1 localhost ... $nameofhost

Cheers!

Method 4

mc -X

worked for me (xterm disabled)

Method 5

Check

host $(hostname)

get quick result

mc use hostname at first to connect to internal service

In similar situation on Fedora 18, I add hostname value to /etc/hosts and it helps.

Method 6

It might start slow because it starts a subshell (shown when you press Ctrl + O) and displays the UI only when the subshell started. I use zsh and I noticed when I remove my ~/.zshrc file mc starts instantly.

Method 7

It took about 10 seconds to start mc. Running strace -r -tt -o mc.strace mc I got:

...
 0.000023 pipe([7, 8])              = 0
 0.000028 clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fcad000fa50) = 3332
 0.000247 write(5, " PROMPT_COMMAND=${PROMPT_COMMAND"..., 75) = 75
 0.000050 rt_sigaction(SIGINT, {0x449960, [], SA_RESTORER, 0x7fcaced23740}, NULL, 8) = 0
 0.000034 select(8, [5 7], NULL, NULL, {10, 0}) = 1 (in [5], left {9, 999996})
 0.000039 read(5, " PROMPT_COMMAND=${PROMPT_COMMAND"..., 128) = 76
 0.000032 select(8, [5 7], NULL, NULL, {9, 999996}) = 1 (in [5], left {9, 985005})
 0.015050 read(5, "[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e198949388a198949388">[email protected]</a> ~]  PROM", 128) = 19
 0.000031 select(8, [5 7], NULL, NULL, {9, 985005}) = 1 (in [5], left {9, 985001})
 0.000036 read(5, "PT_COM", 128)    = 6
 0.000026 select(8, [5 7], NULL, NULL, {9, 985001}) = 1 (in [5], left {9, 984998})
 0.000033 read(5, "MAND=", 128)     = 5
 0.000026 select(8, [5 7], NULL, NULL, {9, 984998}) = 1 (in [5], left {9, 984995})
 0.000033 read(5, "${PR", 128)      = 4
 0.000025 select(8, [5 7], NULL, NULL, {9, 984995}) = 1 (in [5], left {9, 984992})
 0.000034 read(5, "OMPT", 128)      = 4
 0.000025 select(8, [5 7], NULL, NULL, {9, 984992}) = 1 (in [5], left {9, 984989})
 0.000034 read(5, "_COM", 128)      = 4
 0.000026 select(8, [5 7], NULL, NULL, {9, 984989}) = 1 (in [5], left {9, 984986})
 0.000034 read(5, "MAND", 128)      = 4
 0.000025 select(8, [5 7], NULL, NULL, {9, 984986}) = 1 (in [5], left {9, 984983})
 0.000033 read(5, ":+$", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984983}) = 1 (in [5], left {9, 984980})
 0.000033 read(5, "PRO", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984980}) = 1 (in [5], left {9, 984977})
 0.000033 read(5, "MPT", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984977}) = 1 (in [5], left {9, 984974})
 0.000033 read(5, "_CO", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984974}) = 1 (in [5], left {9, 984971})
 0.000033 read(5, "MMA", 128)       = 3
 0.000026 select(8, [5 7], NULL, NULL, {9, 984971}) = 1 (in [5], left {9, 984968})
 0.000032 read(5, "ND;", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984968}) = 1 (in [5], left {9, 984965})
 0.000033 read(5, " }", 128)        = 2
 0.000026 select(8, [5 7], NULL, NULL, {9, 984965}) = 1 (in [5], left {9, 984962})
 0.000033 read(5, "'pw", 128)       = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984962}) = 1 (in [5], left {9, 984959})
 0.000033 read(5, "d>", 128)        = 2
 0.000026 select(8, [5 7], NULL, NULL, {9, 984959}) = 1 (in [5], left {9, 984956})
 0.000032 read(5, "&8;", 128)       = 3
 0.000026 select(8, [5 7], NULL, NULL, {9, 984956}) = 1 (in [5], left {9, 984953})
 0.000032 read(5, "ki", 128)        = 2
 0.000025 select(8, [5 7], NULL, NULL, {9, 984953}) = 1 (in [5], left {9, 984950})
 0.000033 read(5, "ll ", 128)       = 3
 0.000026 select(8, [5 7], NULL, NULL, {9, 984950}) = 1 (in [5], left {9, 984947})
 0.000032 read(5, "-S", 128)        = 2
 0.000025 select(8, [5 7], NULL, NULL, {9, 984947}) = 1 (in [5], left {9, 984944})
 0.000033 read(5, "TO", 128)        = 2
 0.000025 select(8, [5 7], NULL, NULL, {9, 984944}) = 1 (in [5], left {9, 984941})
 0.000033 read(5, "P ", 128)        = 2
 0.000025 select(8, [5 7], NULL, NULL, {9, 984941}) = 1 (in [5], left {9, 984938})
 0.000033 read(5, "$$", 128)        = 2
 0.000033 select(8, [5 7], NULL, NULL, {9, 984938}) = 1 (in [5], left {9, 984935})
 0.000034 read(5, "'rn", 128)     = 3
 0.000025 select(8, [5 7], NULL, NULL, {9, 984935}) = 1 (in [5], left {9, 984886})
 0.000082 read(5, "bash: PROMPT_COMMAND: line 1: sy"..., 128) = 128
 0.000033 select(8, [5 7], NULL, NULL, {9, 984886}) = 1 (in [5], left {9, 984882})
 0.000071 read(5, "tory -r; ; pwd>&8;kill -STOP $$'"..., 128) = 48
 0.000061 select(8, [5 7], NULL, NULL, {9, 984882}) = 0 (Timeout)
 9.995037 rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7fcaced23740}, NULL, 8) = 0
 0.000090 write(1, "33[?1001s33[?1002h33[?1006h", 24) = 24
 0.000066 write(1, "33[?2004h", 8) = 8
 0.000034 geteuid()                 = 1000
 0.000064 access("/home/yuri/.config/mc/filehighlight.ini", R_OK) = -1 ENOENT (No such file or directory)
 0.000061 access("/etc/mc/filehighlight.ini", R_OK) = 0
 0.000042 access("/etc/mc/filehighlight.ini", R_OK) = 0
 0.000044 stat("/etc/mc/filehighlight.ini", {st_mode=S_IFREG|0644, st_size=1119, ...}) = 0
 0.000035 open("/etc/mc/filehighlight.ini", O_RDONLY) = 9
...

Looking at this output, I decided to start mc with empty PROMPT_COMMAND (PROMPT_COMMAND= mc), and it started instantly. I had there supposedly common:

history -a; history -c; history -r;

UPD Upon some more digging, it turns out it has nothing to do with history (PROMPT_COMMAND=';' strace -r -tt -o mc.strace -s 1000 mc):

 0.000197 write(5, " PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'pwd>&8;kill -STOP $$'n", 75) = 75
 0.000068 rt_sigaction(SIGINT, {0x449960, [], SA_RESTORER, 0x7f12567fc660}, NULL, 8) = 0
 0.000049 select(8, [5 7], NULL, NULL, {10, 0}) = 1 (in [5], left {9, 999996})
 0.000055 read(5, " PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'pwd>&8;kill -STOP $$'rn", 128) = 76
 0.000050 select(8, [5 7], NULL, NULL, {9, 999996}) = 1 (in [5], left {9, 981008})
 0.019073 read(5, "bash: PROMPT_COMMAND: line 0: syntax error near unexpected token `;'rnbash: PROMPT_COMMAND: line 0: `;'rn", 128) = 105
 0.000041 select(8, [5 7], NULL, NULL, {9, 981008}) = 1 (in [5], left {9, 980786})
 0.000292 read(5, "[33[1;30myuri33[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccfca18c">[email protected]</a>33[1;33myuri33[0m ~]  PROM", 128) = 41
 0.000070 select(8, [5 7], NULL, NULL, {9, 980786}) = 1 (in [5], left {9, 980782})
 0.000075 read(5, "PT_COMMAN", 128) = 9
 0.000061 select(8, [5 7], NULL, NULL, {9, 980782}) = 1 (in [5], left {9, 980778})
 0.000058 read(5, "D=${PRO", 128)   = 7
 0.000047 select(8, [5 7], NULL, NULL, {9, 980778}) = 1 (in [5], left {9, 980775})
 0.000059 read(5, "MPT_CO", 128)    = 6
 0.000048 select(8, [5 7], NULL, NULL, {9, 980775}) = 1 (in [5], left {9, 980772})
 0.000058 read(5, "MMAND", 128)     = 5
 0.000047 select(8, [5 7], NULL, NULL, {9, 980772}) = 1 (in [5], left {9, 980768})
 0.000056 read(5, ":+$P", 128)      = 4
 0.000047 select(8, [5 7], NULL, NULL, {9, 980768}) = 1 (in [5], left {9, 980764})
 0.000057 read(5, "ROMPT", 128)     = 5
 0.000047 select(8, [5 7], NULL, NULL, {9, 980764}) = 1 (in [5], left {9, 980761})
 0.000056 read(5, "_COM", 128)      = 4
 0.000047 select(8, [5 7], NULL, NULL, {9, 980761}) = 1 (in [5], left {9, 980758})
 0.000057 read(5, "MAND", 128)      = 4
 0.000046 select(8, [5 7], NULL, NULL, {9, 980758}) = 1 (in [5], left {9, 980755})
 0.000057 read(5, "; }'", 128)      = 4
 0.000046 select(8, [5 7], NULL, NULL, {9, 980755}) = 1 (in [5], left {9, 980752})
 0.000056 read(5, "pwd>", 128)      = 4
 0.000047 select(8, [5 7], NULL, NULL, {9, 980752}) = 1 (in [5], left {9, 980749})
 0.000057 read(5, "&8;k", 128)      = 4
 0.000047 select(8, [5 7], NULL, NULL, {9, 980749}) = 1 (in [5], left {9, 980746})
 0.000057 read(5, "ill", 128)       = 3
 0.000058 select(8, [5 7], NULL, NULL, {9, 980746}) = 1 (in [5], left {9, 980743})
 0.000057 read(5, " -ST", 128)      = 4
 0.000046 select(8, [5 7], NULL, NULL, {9, 980743}) = 1 (in [5], left {9, 980740})
 0.000058 read(5, "OP ", 128)       = 3
 0.000046 select(8, [5 7], NULL, NULL, {9, 980740}) = 1 (in [5], left {9, 980736})
 0.000056 read(5, "$$'rn", 128)   = 5
 0.000048 select(8, [5 7], NULL, NULL, {9, 980736}) = 1 (in [5], left {9, 980721})
 0.000069 read(5, "bash: PROMPT_COMMAND: line 1: syntax error near unexpected token `;;'rnbash: PROMPT_COMMAND: line 1: `;; pwd>&8;kill -STOP $$'rn", 128) = 128
 0.000049 select(8, [5 7], NULL, NULL, {9, 980721}) = 1 (in [5], left {9, 980713})
 0.000062 read(5, "[33[1;30myuri33[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eede83ae">[email protected]</a>33[1;33myuri33[0m ~] ", 128) = 36
 0.000047 select(8, [5 7], NULL, NULL, {9, 980713}) = 0 (Timeout)
 9.990855 rt_sigaction(SIGINT, {SIG_IGN, [], SA_RESTORER, 0x7f12567fc660}, NULL, 8) = 0

My conjuncture is that mc messes with PROMPT_COMMAND in a wrong way. It changes PROMPT_COMMAND so that if it contains ;, that triggers bash error. As such, nothing is written to descriptor 8, which blocks the process until timeout. Correct me, if I’m wrong.

Method 8

Just solved the same problem on FreeBSD. I think, it’s more correct to edit /etc/hosts in the following way:

127.0.0.1 localhost localhost.my.domain myhost.my.domain myhost

because the hosts file entry syntax is (see hosts(5) – Linux manual page):

IP_address canonical_hostname [aliases...]

So, if you just add in your hosts file something like

127.0.0.2 myhost.my.domain myhost

then you will get

<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81f3eeeef5c1ecf8e9eef2f5">[email protected]</a>:~# ping myhost
PING myhost.my.domain (127.0.0.2): 56 data bytes
ping: sendto: Can't assign requested address
ping: sendto: Can't assign requested address
ping: sendto: Can't assign requested address
ping: sendto: Can't assign requested address
^C
--- myhost.my.domain ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss

But if you edit your hosts file like in the first example, you will get the correct ping answer:

<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a4855554e7a57435255494e">[email protected]</a>:~# ping myhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.060 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.050 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.030 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.040 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.046 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.036 ms
^C
--- localhost ping statistics ---
6 packets transmitted, 6 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.030/0.044/0.060/0.010 ms

MC starts fast both ways.

Method 9

I had this issue for a very long time and I ended up not using Midnight Commander anymore…

But I recently found the solution!!! In my case, it was only related to my alternative shell: I’m using fish. http://fishshell.com/

The two together doesn’t work great. I just changed my script to make sure mc use bash and not fish.

Method 10

DISPLAY=;mc

works for me.
Using MobaXterm X11-Forwarding, automatic DISPLAY redirection.

Method 11

If you are using MobaXterm to connect to SSH on your server you may need to turn off X11 forwarding to start mc shortly. This is what slows down the mc start.

Method 12

In my case, 10 seconds of slow down was because of

[oh-my-zsh] Would you like to update? [Y/n]

Method 13

Try to delete line “search whatever.something” from /etc/resolv.conf

/etc/hosts should have the lines:

127.0.0.1 localhost

127.0.0.2 hostname.domain hostname

“hostname” is your hostname and “domain” is your domain.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x