scriptfor instanceruns the child function in child processes only because forking is ingrained in the unix programming modelthis script works well on unixlinuxand modern macs unfortunatelythis script won' work on the standard version of python for windows todaybecause fork is too much at odds with the windows model python scripts can always spawn threads on windowsand the multi processing module described later in this provides an alternative for running processes portablywhich can obviate the need for process forks on windows in contexts that conform to its constraints (albeit at some potential cost in low-level controlthe script in example - does work on windowshoweverif you use the python shipped with the cygwin system (or build one of your own from source-code with cygwin' librariescygwin is freeopen source system that provides full unix-like functionality for windows (and is described further in "more on cygwin python for windowson page you can fork with python on windows under cygwineven though its behavior is not exactly the same as true unix forks because it' close enough for this book' examplesthoughlet' use it to run our script live[ :\pp \system\processes]python fork py hello from parent hello from child hello from parent hello from child hello from parent hello from child these messages represent three forked child processesthe unique identifiers of all the processes involved are fetched and displayed with the os getpid call subtle pointthe child process function is also careful to exit explicitly with an os _exit call we'll discuss this call in more detail later in this but if it' not madethe child process would live on after the child function returns (rememberit' just copy of the original processthe net effect is that the child would go back to the loop in parent and start forking children of its own ( the parent would have grandchildrenif you delete the exit call and rerunyou'll likely have to type more than one to stopbecause multiple processes are running in the parent function in example - each process exits very soon after it startsso there' little overlap in time let' do something slightly more sophisticated to better illustrate multiple forked processes running in parallel example - starts up copies of itselfeach copy counting up to with one-second delay between iterations the time sleep standard library at least in the current python implementationcalling os fork in python script actually copies the python interpreter process (if you look at your process listyou'll see two python entries after forkbut since the python interpreter records everything about your running scriptit' ok to think of fork as copying your program directly it really will if python scripts are ever compiled to binary machine code parallel system tools