43

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

3
  • 1
    Did you compile it with --enable-vfs-smb? Try disabling the feature. Seems to be a common problem with version 4.8.4: mc starting up very SLOW
    – Marco
    Dec 3, 2012 at 12:25
  • 3
    Run strace -r -tt -o mc.strace mc to see where it's taking time. Upload the trace file if you need help interpreting it. Note that the trace file may contain private information (at least file names), take a look at it and sanitize it if necessary before uploading. Dec 3, 2012 at 21:38
  • 1
    had the same problem, added hostname to /etc/hosts (as 127.0.0.1, of course), all became perfect
    – user138908
    Oct 16, 2015 at 21:33

14 Answers 14

52

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

alias mc="mc --nosubshell"
5
  • 3
    This was the only solution that worked for me. I can see that I have access to cmd-o, but I can't type any commands.
    – Panayotis
    Jan 27, 2018 at 9:43
  • doesnt work for me
    – stiv
    Jul 29, 2018 at 12:28
  • 3
    This solution makes MC starts on mac instantaneously. Otherwise it takes 7 seconds. Jan 16 at 15:48
  • a handy shorter option is mc -u Mar 9 at 10:39
  • it works for me
    – alinsoar
    Aug 2 at 10:33
15

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.

2
  • Why did you use 127.0.0.2 but not 127.0.0.1?
    – Dims
    Dec 11, 2017 at 15:08
  • any x,y,z in 127.x.y.z will work equally well (the entire IP range is reserved for the local machine)
    – ggpp23
    Jan 30, 2018 at 18:07
14
mc -X

worked for me (xterm disabled)

3
  • 2
    This was the problem for me as well. DISPLAY environment variable was set to localhost:10.0, but there was no X server listening there on that server with no display.
    – fviktor
    Dec 7, 2019 at 12:56
  • 3
    For me mc -u -X helped (disabling xterm + subshell). Sep 15, 2020 at 7:22
  • 1
    mc -X solved problem for me, but mc -u -X is more faster than just -X.
    – rzlvmp
    Dec 22, 2022 at 4:43
10

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!

1
  • This solution also works if the samba connection is (extremly) slow. Sep 10, 2020 at 12:14
6

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.

6
  • mc internal service? may be we could change some configuration to fix mc to not require changing /etc/hosts? or is the /etc/hosts broken and mc expects it to be corrected? Jan 22, 2015 at 21:20
  • oh, I just found that this works here: alias mc='TERM=linux mc' Jan 22, 2015 at 21:29
  • 1
    Really /etc/hosts is broken, from some point of view. Impossible to resolve own hostname to own ip. I don't know why mc depend on it there.
    – mmv-ru
    Jan 22, 2015 at 22:32
  • 1
    What do you mean by host 'hostname'? It returns the same as host 'aaaa', host 'aaab' and the endless list of non-existing hosts. Did yoy mean MC is trying to resolve non-existing host?
    – Dims
    Feb 23, 2017 at 13:46
  • Sorry, apostrophe must be there in place of single quotes. Answer fixed. In some way Yes. MC make connection to own server by Your hostname, so it get nonexistent host and make many tries.
    – mmv-ru
    Feb 23, 2017 at 19:42
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.

2
3

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, "[yuri@yuri ~]  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, "'\r\n", 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[?1001s\33[?1002h\33[?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 $$'\r\n", 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 `;'\r\nbash: PROMPT_COMMAND: line 0: `;'\r\n", 128) = 105
 0.000041 select(8, [5 7], NULL, NULL, {9, 981008}) = 1 (in [5], left {9, 980786})
 0.000292 read(5, "[\33[1;30myuri\33[0m@\33[1;33myuri\33[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, "$$'\r\n", 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 `;;'\r\nbash: PROMPT_COMMAND: line 1: `;; pwd>&8;kill -STOP $$'\r\n", 128) = 128
 0.000049 select(8, [5 7], NULL, NULL, {9, 980721}) = 1 (in [5], left {9, 980713})
 0.000062 read(5, "[\33[1;30myuri\33[0m@\33[1;33myuri\33[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.

4
  • 1
    I know this is an old answer and all. But maybe I am lucky and you mind explaning why you conclude from the strace output that something was wrong with PROMPT_COMMAND. I had the same issue and I also solved it by removing history -a from my PROMPT_COMMAND but I have no idea why that helps and I have no idea where the connection between that and select(8, [6,7], ...) (which apparently causes the slow down of MC with the timeout) is. Maybe you can help me understand the solution.
    – degill
    Aug 29, 2015 at 18:50
  • @degill Please see my updated answer.
    – x-yuri
    Aug 29, 2015 at 22:39
  • Thanks for the update! You are right, just putting ; in the PROMPT_COMMAND does have the same effect of timing out. I know added history -a back to my PROMPT_COMMAND (within ~/.local/share/mc/bashrc) and everything works fine. Still interesting though what is up with the ;
    – degill
    Aug 30, 2015 at 9:51
  • 5
    The upstream bug entry is at midnight-commander.org/ticket/3534.
    – egmont
    Oct 12, 2015 at 19:40
3

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

root@myhost:~# 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:

root@myhost:~# 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.

2

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.

1
  • And why would fish cause such problems? Nov 17, 2016 at 13:39
1

DISPLAY=;mc

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

1
  • This may happen when the X-server is not up (specified by DISPLAY).
    – ern0
    Feb 25, 2022 at 7:44
0

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.

0

I used to have exactly the same problem.
Usually it was due to missing hostname line in /etc/hosts,
but this time the reason turned out quite different - the file ".bashrc" , to be specific these lines:

# The next line updates PATH for Yandex Cloud CLI.
if [ -f '/home/vasya/yandex-cloud/path.bash.inc' ]; then source '/home/vasya/yandex-cloud/path.bash.inc'; fi

# The next line enables shell command completion for yc.
if [ -f '/home/vasya/yandex-cloud/completion.bash.inc' ]; then source '/home/vasya/yandex-cloud/completion.bash.inc'; fi

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

When i remove them the launch time of mc diminished from two seconds to just instant.

So the proposition - if none of the above solutions help - try to investigate ".bashrc"

-1

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

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

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.

1
  • That makes some sense only if the machine is never connected to the 'net. That file is filled in by DHCP (or when the Internet connection is configured).
    – vonbrand
    Jan 26, 2013 at 3:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .