I have a bash session open to a remote server and something is wrong. I created a directory "test" and touched the files inside touch 1 2 3 4 5. I then tried to copy the directory cp test/ test2/ and it hung. Killed it with ^C; entered the directory and tried to cp 1 2; it hung as well.

I then tried to do a ls and got the following error:

-bash: fork: Cannot allocate memory

Now, I know that there is memory available. I logged in from another terminal which defaults to my home directory. touch 1 and cp 1 2 and it hangs. I can ls though..

Logged in as root and tried to cp 1 2 from the same directory and it works. No problems from the root account.

Lots of memory free:

#free -h
              total        used        free      shared  buff/cache   available
Mem:           188G         87G        3.4G        1.8G         97G        3.3G
Swap:          3.9G        3.8G        140M

I've still got the other ssh session which is giving my allocation errors opened for testing. What is going on?

Update 1

I tried running cp 1 2 from the terminal that I can still from commands from but hangs and then top -b | grep -w bash from my root accout. The cp command never shows.

The other terminal which was reporting memory allocation problems is now responding to ls but still hangs with cp 1 2.

Update 2

The problem was a misconfiguration in the shared .bashrc:

function cp() {
   cp --preserve=all --no-dereference $@

Whereas it should have been setup as:

alias cp='cp -adR'
  • Try running the same commands and in a separate SSH session run top while the command is running. That should give you an idea as to whats happening. Can you post your results in your question? – ryekayo Sep 6 '15 at 23:21
  • Updated the original question. – Zhro Sep 6 '15 at 23:47
  • Run strace cp 1 2 and see where something goes wrong. Or run strace -f -p1234 from another terminal where 1234 is the PID of the bash process where you get the errors, and then run cp 1 2 in that bash process. – Gilles Sep 6 '15 at 23:49
  • 3
    Can you try type cp and see that you are accessing the appropriate version. Possibly, you can also issue the absolute path of cp in the command. – unxnut Sep 7 '15 at 0:05
  • Brownie points to unxnut for helping track down the snafu. type cp pointed directly to the erroneous function. Resubmit as an answer and I'll accept it. Gilles answer was also good but strace called the program cp instead of the bash function and exited fast and cleanly with no hang and still left me hunting. – Zhro Sep 7 '15 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.