Run Codes in the Background in Server
To use screen to run ./race_full.py in one session and ./race_last.py in another, here’s how you can do it:
-
Start a New Screen Session for
race_full.py:-
Create and name the session for
race_full.py:screen -S session_name -
Inside this screen session, run the script:
./race_full.py -
Detach from the session by pressing
Ctrl+A``D. This will keeprace_full.pyrunning in the background.
-
-
Start Another Screen Session for
race_last.py:-
Create and name the session for
race_last.py:screen -S session_name -
Inside this screen session, run the script:
./race_last.py -
Detach from this session as well using
Ctrl+AthenD.
-
-
Check and Manage Screen Sessions:
-
To view your active sessions, use:
screen -ls -
You should see both
race_fullandrace_lastlisted, either as(Attached)or(Detached).
-
-
Reattach to a Session:
-
If you want to reattach to a session, specify its name. For example:
,race_full -
To reattach to
race_last:screen -r race_last
-
This setup will keep both scripts running independently, and you can freely detach and reattach as needed to monitor their progress.