Skip to content

Instantly share code, notes, and snippets.

@sandys
Last active September 17, 2024 17:27
Show Gist options
  • Save sandys/a5f0c4ac3b632f08f0a0ae185ca99fc6 to your computer and use it in GitHub Desktop.
Save sandys/a5f0c4ac3b632f08f0a0ae185ca99fc6 to your computer and use it in GitHub Desktop.
running anything in the background (very simply!!)

How to setup cursor.sh so that you are able to use it on remote server with tmux

add the following to your settings.json

image

{
  "terminal.integrated.profiles.linux": {
    "tmux": {
      "path": "/usr/bin/tmux",
      "args": [
        "new-session",
        "-A",
        "-s",
        "tmux-${workspaceFolderBasename}"
      ],
    },
  },
  "terminal.integrated.defaultProfile.linux": "tmux",
}```


How to Run a Process in the Background with TMUX

There are times when you need to shutdown your laptop, and you want a server process (like a chromium compile) to run in the background. TMUX manages this very well. you dont need to figure some weird "&" syntax or anything

For this example, let's suppose you're running a long running task like running rspecs on your project and it is 5pm, and you need to go home.

Run Your Process

1. First launch TMUX

$ tmux new-session -A -s  sss1

Start a new session or attach to an existing session named sss1

2. Run your long running process

$ something long long long 

3. Detach from TMUX

Simply press [CTRL]+[b] (together and then leave them), then [d]. This will detach your session from TMUX.

NOTE: you can do this while your long process is running. Dont be afraid!

4. Log off

Now you can simply log off

Show all sessions on the computer

$ tmux ls

this will show you all running sessions

root@Ubuntu-2404-noble-amd64-base ~ # tmux ls
sss1: 1 windows (created Sat Aug 31 21:31:41 2024)
sss2: 1 windows (created Sat Aug 31 21:31:44 2024)

Return to your session

When you return back to your desktop, open a terminal and simply run:

$ tmux new-session -A -s  sss1

This will attach to your detached TMUX session. you will see all the screen output and everything. its just like as if ur terminal was running and you just opened it now. no mess of background processes.

Anytime u want to detach again, simply press [CTRL]+[b], then [d]. to exit, just type exit in ur tmux session. that session ends.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment