TCSETSID(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– TCSETSID(3) πŸ’–

okay so bestie, this is a page from the Library Functions Manual, and it’s about a lil function that hooks a session up to a controlling terminal. slay, but with rules. πŸ’…

✨ NAME ✨

tcsetsid β€” set session ID associated with a controlling terminal 🫢

🌸 LIBRARY 🌸

Standard C Library (libc, -lc) πŸŽ€

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <termios.h>

int
tcsetsid(int fd, pid_t pid);

🌈 DESCRIPTION 🌈

okay so tcsetsid() associates a session identified by pid with a controlling terminal specified by fd. that’s the whole vibe. ✨

but here’s the catch, and it’s kind of a big one: this implementation only allows the controlling terminal to be changed by the session leader itself. which means pid always has to be equal to the process ID. no cap. πŸ‘‘

also, it is unsupported to associate with a terminal that already has an associated session. and conversely, it is also unsupported to associate to a terminal when the session is already associated with a different terminal. so yeah, no messy love triangles between sessions and terminals. πŸ’€

πŸ’… ERRORS πŸ’…

if something goes wrong, tcsetsid() returns -1 and the global variable errno is set to indicate the error, as follows:

  • [EBADF] β€” the fd argument is not a valid file descriptor. πŸ™ˆ
  • [ENOTTY] β€” the file descriptor represented by fd is not a terminal. 😭
  • [EINVAL] β€” the pid argument is not equal to the session ID of the calling process. ⭐
  • [EPERM] β€” the calling process is not a session leader. 🫠
  • [EPERM] β€” the session already has an associated terminal, or the terminal already has an associated session. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

getsid(2), setsid(2), tcgetpgrp(3), tcgetsid(3) πŸ¦‹

πŸŽ€ HISTORY πŸŽ€

a tcsetsid() function first appeared in QNX. it does not comply to any standard. iconic behavior, honestly. πŸ’–


mwah πŸ’‹ β€” this page is from Debian, dated November 28, 2022, and it’s the TCSETSID(3) manual page. πŸ“

πŸ“¦ where this page comes from