Unix to Windows Porting Dictionary for HPC

Links

Function List

setsid


Table of Contents

Unix
Windows
Purpose
Discussion

Unix

header file: unistd.h

pid_t setsid(void);

Windows

header file: n/a

Purpose

This function creates a new Unix session.

Discussion

On Unix systems this function created a new session and set the calling process as the leader of the session. Initially the calling process is the only member of the session. Processes within the same session share the same controlling terminal.

On Windows there is not a matching function or one with similar functionality. There is a paradigm difference between Unix and Windows. Windows does not have sessions to group processes together, nor the does it have controlling terminals for processes.

You will need to examine the source code to determine the reason the process wants to start a new session. Typically a new session is started to group one or more processes together for the delivery of signals and/or to associate them with a common controlling terminal. Often this is done as a Unix login shell is started at a terminal or modem line for a user newly connecting to the system.

Since Windows does not send signals, does not have controlling terminals, and does not have job control, it is difficult to map the intended functionality of setsid(). Typically the source code change is to conditionalize this code so it is only used on Unix systems with no matching action on Windows. Then the parent process will maintain a local list of child processes if one or more or all need to be terminated. A restructuring of the code may need to be done because of signals sent between processes. The setsid() function call is likely done within a Unix context that must change on Windows.

blog comments powered by Disqus