Chet Ramey wrote in
 <7402031f-424c-4766-ba70-71771c9dc...@case.edu>:
 |On 11/8/23 8:12 PM, Steffen Nurpmeso wrote:
 |> The "problem" with the current way bash is doing it is that bash's
 |> job handling does not recognize jobs die under the hood:
 |> 
 |>    $ jobs
 |>    [1]-  Stopped                 LESS= less -RIFe README
 |>    [2]+  Stopped                 LESS= less -RIFe TODO
 |>    $ kill $(jobs -p)
 |>    $
 |> 
 |> ^ nothing
 |> 
 |>    $ jobs
 |>    [1]-  Stopped                 LESS= less -RIFe README
 |>    [2]+  Stopped                 LESS= less -RIFe TODO
 |
 |Yes, the jobs are still stopped, and will remain stopped until they get
 |a SIGCONT. Do you think that kill, when given a pid argument, should look
 |up any job associated with that pid and send it a SIGCONT? Or should it
 |send a SIGCONT to the pid unconditionally? If so, what about other
 |processes in that job?

Today GMANE (through which i read bug-bash@) posted this entire
thread again!  And because i am a bit afraid of Danish dynamite
(especially relaxed, or on-holiday such sort), i thought i better
do something.  So what i did was as below (any usage of job_by_pid
without args 2+3==0?), and i even compiled and tested it (a bit).
Maybe you like it!

Ciao already here!

diff --git a/builtins/kill.def b/builtins/kill.def
index c655092e7b..e3caabbf73 100644
--- a/builtins/kill.def
+++ b/builtins/kill.def
@@ -85,6 +85,11 @@ int
 kill_builtin (list)
      WORD_LIST *list;
 {
+#if defined (JOB_CONTROL)
+  sigset_t set, oset;
+  JOB *j;
+  int job;
+#endif
   int sig, any_succeeded, listing, saw_signal, dflags;
   char *sigspec, *word;
   pid_t pid;
@@ -194,6 +199,14 @@ use_sigspec:
        {
          pid = (pid_t) pid_value;
 
+#if defined (JOB_CONTROL)
+         BLOCK_CHILD (set, oset);
+         job = get_job_by_pid ((pid_t) pid_value, 0, 0);
+         if (job != NO_JOB)
+           goto jisjob;
+         UNBLOCK_CHILD (oset);
+#endif
+
          if (kill_pid (pid, sig, pid < -1) < 0)
            {
              if (errno == EINVAL)
@@ -214,10 +227,6 @@ use_sigspec:
       else if (*word)
        /* Posix.2 says you can kill without job control active (4.32.4) */
        {                       /* Must be a job spec.  Check it out. */
-         int job;
-         sigset_t set, oset;
-         JOB *j;
-
          BLOCK_CHILD (set, oset);
          job = get_job_spec (list);
 
@@ -229,6 +238,7 @@ use_sigspec:
              CONTINUE_OR_FAIL;
            }
 
+jisjob:
          j = get_job_by_jid (job);
          /* Job spec used.  Kill the process group. If the job was started
             without job control, then its pgrp == shell_pgrp, so we have

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
|
| Only in December: lightful Dubai COP28 Narendra Modi quote:
|  A small part of humanity has ruthlessly exploited nature.
|  But the entire humanity is bearing the cost of it,
|  especially the inhabitants of the Global South.
|  The selfishness of a few will lead the world into darkness,
|  not just for themselves but for the entire world.

Reply via email to