A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/linux-unix/setsid-command-in-linux-with-examples/ below:

setsid command in Linux with Examples

setsid command in Linux with Examples

Last Updated : 23 Sep, 2024

setsid command in Linux system is used to run a program in a new session. The command will call the fork(2) if already a process group leader. Else, it will execute a program in the current process. The main advantage of using 'setsid' is that it allows programs to run independently of the terminal that launched them, making it an ideal solution for running long-lasting background jobs or services.

Syntax:
setsid [options] program [arguments]

where,

Basic 'setsid' command Example

It will execute our shell script in a new session.

Commonly Used Options for 'setsid' 1. setsid -c:

This option will set the controlling terminal to the current one.

Example:

sudo setsid -c ./add.sh

In this example, we have our current terminal set to controlling terminal.

2. setsid -w:

This option will wait for the execution of the program to end and return the exit value of this program as the return value of setsid.

Example:

setsid -w ./add.sh

In this example, if there's any process which is supposed to take some time to be fully executed then, in that case, it will return the exit value.

3. setsid -V:

This option will show the version information and exit.

Example:

setsid -V
4. setsid -h:

This option will show the help text and exit.

setsid -h

This will show a brief overview of available options and their usage.

Conclusion

The 'setsid' command in Linux is an essential tool for running programs and scripts in new sessions, making them independent of the terminal. setsid provides a simple and efficient way to achieve these goals. With its various options, setsid is a versatile command that enhances process management and improves workflow.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4