« first day (2924 days earlier)      last day (690 days later) » 

10:13 AM
@Kcvin You sure You need "pre-standard" preprocessor? o_0
 
 
2 hours later…
11:47 AM
lol
 
 
9 hours later…
8:53 PM
Allegedly, the shell should "arranges that the program will ignore interrupts" when run non-interactively, e.g. ./my_program &
However, I find that interrupts are not already ignored? Consider the following program:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main (void)
{
    extern void interrupt_handler(int);

    // Signal test
    if (SIG_IGN == signal(SIGINT, SIG_IGN)) {
        fprintf(stderr, "Note: Interrupts are already ignored!\n");
    } else {
        fprintf(stderr, "Note: Installing interrupt handler!\n");
        signal(SIGINT, interrupt_handler);
    }

    // Do some shit
    usleep(10 * 10000000);

    return 0;
}

void interrupt_handler (int s)
{
    printf("interrupt handler invoked!\n");
Irrespective of how I invoke it, interrupts are not already ignored. So this information is either outdated, or I am doing something wrong.
Any ideas?
 
 
1 hour later…
10:22 PM
@Micrified mhm, what? Why should it be (or all of them?) ignored? You still wan't to do CTRL+C, right? Which is common way to send SIGINT....
can it be related to some particular shell? Not even sure how could it mask it... but maybe it's doable as a parent process or something...
mhm. Just missed the "& and non-interactive" part entirely :D
but yeah, at least in terms of bash, "&" does not mean it's gonna be executed non-interactively. It means, that's it's gonna be ran in a sub-shell and so called "in a background":
> "If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell. This is known as executing the command in the background, and these are referred to as asynchronous commands. The shell does not wait for the command to finish, and the return status is 0 (true). When job control is not active (see Job Control), the standard input for asynchronous commands, in the absence of any explicit redirections, is redirected from /dev/null."
And again, from the bash man-page:
> "SIGNALS
When bash is interactive, in the absence of any traps, it ignores SIGTERM (so that kill 0 does not kill an interactive shell), and SIGINT is caught and handled (so
that the wait builtin is interruptible). In all cases, bash ignores SIGQUIT. If job control is in effect, bash ignores SIGTTIN, SIGTTOU, and SIGTSTP.

Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchronous
commands ignore SIGINT and SIGQUIT in addition to these inherited handlers. Commands run as a result o
> " The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are
sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table
with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to not receive SIGHUP using disown -h.

If the huponexit shell option has been set with shopt, bash sends a SIGHUP to all jobs when an interactive login shell exits.
 
10:39 PM
@Kamiccolo If you run my_program &, then you don't want CTRL-C to affect it right?
 
@Micrified ok, after checking this: unix.stackexchange.com/a/137917/34050
 
It should only affect foreground programs
@Kamiccolo Oh
lmao I'm replying too early
 
1. You have to disable job control by executing `set +m`
2. execute in a background ./a.out &
3. kill -2 PID does not work anymore ;)
 
FWIW "non-interactively" are the words chosen by the book authors
 
I'd presume that "non-interactively" means in the background with job control off (default for bash is on). Being able to stop, suspend, continue, etc means it's interactive. Isn't it?
 
10:44 PM
Thanks this line is critical: "Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchronous
commands ignore SIGINT and SIGQUIT in addition to these inherited handlers"
@Kamiccolo They seem to use the word interactive to refer to a program that requires user input.
 
@Micrified some of the signals is user input :D
 
So like any editor program, or one that prompts the user for decisions
I would say signals aren't normal user input.
But guess it's interpretable in other ways
 
@Micrified probably. That's why it feels like... specific to some particular shell. I wonder, if POSIX is saying anything about that...
@Micrified even SIGUSR1, SIGUSR2? :D
 
@Kamiccolo I mean the book mentioned nothing about job control so it may not have existed in their version of bash in 198X
@Kamiccolo I'm going to pretend I didn't see that.
 
@Micrified that makes sense. Maybe there was no such a thing as background/foreground back then? No idea. Need to dig through history :D
 
10:54 PM
@Kamiccolo I feel they would have mentioned it if it was.
There was largely a section on shell usage.
I checked the book index, and there is indeed nothing in the j section about jobs
:D
 
> "Well into the 1980s, most users only had simple character-mode terminals that precluded multiple windows, so they could only work on one task at a time. The C shell's job control allowed the user to suspend the current activity and create a new instance of the C shell, called a job, by typing ^Z. The user could then switch back and forth between jobs using the fg command...."
> " The active job was said to be in the foreground. Other jobs were said to be either suspended (stopped) or running in the background."
can't find this nice github page with Unix history and timeline of it's utilities evolution :|
 
The C shell refers to csh right?
I don't believe they use this shell in the book.
I know because bsd does use csh natively I think (BSD 14.0)
 
yeah
aha, according to this: https://dspinellis.github.io/unix-history-man/man1.html
bg and fg appeared in BSD 4.3, so.... 1986 :D
 
Well this version of the book is stamped 1984 according to the publisher copyright
So yeah :D
 

« first day (2924 days earlier)      last day (690 days later) »