Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job control #238

Open
22 of 25 tasks
Tracked by #41
magicant opened this issue Jan 27, 2023 · 0 comments
Open
22 of 25 tasks
Tracked by #41

Job control #238

magicant opened this issue Jan 27, 2023 · 0 comments
Labels
tracker List of subtasks

Comments

@magicant
Copy link
Owner

magicant commented Jan 27, 2023



We must not create a process group for a built-in in a single-command pipeline, so we need to handle single-command and multi-command pipelines separately.

Questions:

  • When should the shell move itself back to the foreground?
    • For consistency and stability, the shell should move itself back to the foreground after running each job rather than only before performing I/O.
  • Does the parent process need to call setpgid after forking? → Yes, at least for the background job
    • The fg and bg built-ins have to send a SIGCONT to the target job, which must have been created. The parent process has to make sure the child is in its own process group when starting the job.
  • Does the parent process need to call tcsetpgrp after forking? → No
    • The shell have to call setpgid and tcsetpgrp to turn a child process into a foreground job. Since the two function cannot be called atomically, the job is in the background between the two calls. The child process has to call tcsetpgrp to bring itself to the foreground before starting its task.
    • The child blocks SIGTSTP until it finishes tcsetpgrp. Therefore, if the child stops, it has called tcsetpgrp, so it won't call tcsetpgrp after it is resumed (either in the foreground or background).
    • When the parent finishes waiting for the child to terminate or stop, the child must have called tcsetpgrp, so it is surely in the foreground.
  • The shell should suspend itself if it is in the background when it is manipulating jobs. Exactly when?
    • An interactive shell ignores SIGTTIN, SIGTTOU, and SIGTSTP by default, so it should not rely on automatically sent signals to stop it. Instead, it should "kill" itself or call tcsetpgrp to suspend itself.
    • When the shell starts a foreground job, the shell should be in the foreground.
    • When the shell starts a background job, the shell does not have to be in the foreground.
    • When the shell runs a built-in, the shell should be in the foreground because the (non-special) built-in should behave the same as the corresponding external utility.
    • To sum up, it will suffice for the shell to check the foreground-ness before running each pipeline.
  • Implication of suspending a process that is not a direct child of the job-controlling shell #299
@magicant magicant mentioned this issue Jan 27, 2023
26 tasks
@magicant magicant changed the title job control Job control Jan 27, 2023
@magicant magicant added the tracker List of subtasks label Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracker List of subtasks
Projects
Status: To do
Development

No branches or pull requests

1 participant