Search code examples
linuxshellbackground-process

Running several background processes in linux using own shell script launcher


I would like to run several application instances in a remote Linux server which would run in a parallel way and also after logging out. I would like to launch them using a single shell script.

Let's say that I want to run the following commands in a parallel way:

matlab -nodisplay -r "matlab_test"
matlab -nodisplay -r "matlab_test2"

And let's say these processes update files named "test_file.mat" and "test_file2.mat" respectively as frequently as possible.

I tried several methods that I googled out, but here are the most representative ones.

  1. I tried the following combination, in order to use it in the future shell script:

    matlab -nodisplay -r "matlab_test" &
    bg 1
    

    Result: the output file "test_file.mat" was not generated at all, so I assume that the process was put to the background, but it was not running there.

    Remark: When I fg this process, the file is generated.

  2. I also tried:

    nohup matlab -nodisplay -r "matlab_test" &
    

    Result: the command prompt was occupied, which, as I assume, prevents from calling the next commands.


Solution

  • Try nohup matlab "matlab_test" &

    that should work.