Review Glossary FR

Size

Eyes

Finish a part in any dojo to unlock the next eyes.

Day 1 10 min

How a process starts

1 / 10 · ≈ 9 min left

The problem

You run ./setenv.sh, a script with two lines: cd /tmp and export DB_URL=postgres://db/app. It prints in script: /tmp postgres://db/app. Back at the prompt, pwd still prints your home directory and echo $DB_URL prints an empty line.

The script ran in a second process. Bash called fork() to copy itself, and the copy called execve() to load /bin/bash on the script. In the test run, the script printed pid=4044147 ppid=4044145: its parent was the shell, PID 4044145.

The cd and the export changed the working directory and the variables of process 4044147 only. When that process exited, its directory and its variables were gone. . ./setenv.sh runs the same two lines inside the shell itself, and then they stay.