P
P
Pavel Kulaga2020-02-06 20:43:47
terminal emulator
Pavel Kulaga, 2020-02-06 20:43:47

How does zsh organize the processing of such a command: "cat &"?

I'm writing shell , but I can't figure out how to handle cat & .
What is the background process and why is the SIGTTOU signal raised.
"SIGTTOU is the signal sent to a background task when trying to output to the controlling terminal"
zsh outputs this, but I have no idea how it handles it at all.

> cat &
[2] 10810
[2]  + suspended (tty input)  cat

Does anyone have material about this or know how to organize it?
In my usual case, I have:
if ((pid = fork()) == 0)
{
  ft_42sh_signal_default();//Востановим сигналы
  tcsetattr(STDIN_FILENO, TCSANOW, &array->tty);//Установим каонический режим
  execve(lp_arg[0], lp_arg, env_spl);//Запускаем
}
else
      wait//ждем

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Kulaga, 2020-02-08
@hapr-lera

Shells do this by creating setpgid process groups .
And then if it is "cat" then bring tcsetattr to the foreground and wait for wait . If "cat &" then leave it in the background.

A
Armenian Radio, 2020-02-06
@gbg

This is a personal matter of the terminal. When a process starts, the terminal gives it its descriptors in, out, err.
When you run a process in the background, the terminal doesn't hook those threads to the screen and keyboard, that's all.
That is, this is not some kind of system call, but the implementation of a certain work strategy.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question