job control for a shell under linux

job control for a shell under linux

Post by Delon Nicola » Mon, 01 May 2000 04:00:00



I write a shell who must run under NetBSD, but I'm a fan of
Linux, so I'd like that it could run also under Linux.

So here is my problem :

actually i do the job control, i write few lines are efficient under
netbsd
but who doesn't work under linux.

so here is my piece of my code with annotation :

/*
** exec_cmd.c for  in
**
** Made by nicolas delon

**
** Started on  Fri Jan 21 12:31:06 2000 nicolas delon
## Last update Fri Apr 28 09:26:48 2000 nicolas delon
*/

#include "my/my.h"
#include "shell.h"
#include <fcntl.h>
#include <signal.h>

void    exec_cmd(char *cmd[], int bg)
{
  int   pid;

  signal(SIGCHLD, waiting);
  if ((pid = fork()) == -1)
    {
      perror("mysh");
      return;
    }
  else if (pid)
    {
      if (bg)
        return;
      else
        {
          setpgid(pid, pid);
          tcsetpgrp(open("/dev/tty", O_RDONLY), pid)
          pause();
          tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())       /* here
is the mistake, the child die, the father continue
                                                                   and
he reveices a SIGTTOU
                                                                   under
Linux (it works under NetBSD), and it stops*/
        }
    }
  else
    {
      usleep(1);
      setpgid(getpid(), getpid());
      if (!bg)
        {
          tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())
        }
      cmd = redirections(cmd);
      if (execvp(cmd[0], cmd) == -1)
        {
          aff_error("mysh: ");
          aff_error(cmd[0]);
          aff_error(": ");
          aff_error("command not found\n");
          exit(0);
        }
    }

Quote:}

so if anybody have a solution for this problem....
 
 
 

job control for a shell under linux

Post by Andrew Giert » Mon, 01 May 2000 04:00:00


 Delon> I write a shell who must run under NetBSD, but I'm a fan of
 Delon> Linux, so I'd like that it could run also under Linux.

 Delon> So here is my problem :

 Delon>           tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())
 Delon>      /* here is the mistake, the child die, the father
 Delon> continue and he reveices a SIGTTOU under Linux (it works under
 Delon> NetBSD), and it stops*/

You need to block SIGTTOU around the call to tcsetpgrp. This is a
misfeature of the POSIX standard (some dimwit decided that _all_
terminal attribute changes should generate SIGTTOU from a background
process, neglecting to consider the fact that this is the _normal_
case for tcsetpgrp); some of the *BSDs don't conform strictly.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>

 
 
 

job control for a shell under linux

Post by Delon Nicola » Mon, 01 May 2000 04:00:00




>  Delon> I write a shell who must run under NetBSD, but I'm a fan of
>  Delon> Linux, so I'd like that it could run also under Linux.

>  Delon> So here is my problem :

>  Delon>           tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())
>  Delon>      /* here is the mistake, the child die, the father
>  Delon> continue and he reveices a SIGTTOU under Linux (it works under
>  Delon> NetBSD), and it stops*/

> You need to block SIGTTOU around the call to tcsetpgrp. This is a
> misfeature of the POSIX standard (some dimwit decided that _all_
> terminal attribute changes should generate SIGTTOU from a background
> process, neglecting to consider the fact that this is the _normal_
> case for tcsetpgrp); some of the *BSDs don't conform strictly.

> --
> Andrew.

> comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
>                            or <URL: http://www.whitefang.com/unix/>

OK it works (linux and netbsd) by adding signal(SIGTTOU, SIG_IGN),

i ignore the SIGTTOU but would it be better to block it ?

 
 
 

job control for a shell under linux

Post by Antoine LAUREN » Fri, 05 May 2000 04:00:00


Aren't u in EPITA ?

        ;-)



> I write a shell who must run under NetBSD, but I'm a fan of
> Linux, so I'd like that it could run also under Linux.

> So here is my problem :

> actually i do the job control, i write few lines are efficient under
> netbsd
> but who doesn't work under linux.

> so here is my piece of my code with annotation :

> /*
> ** exec_cmd.c for  in
> **
> ** Made by nicolas delon

> **
> ** Started on  Fri Jan 21 12:31:06 2000 nicolas delon
> ## Last update Fri Apr 28 09:26:48 2000 nicolas delon
> */

> #include "my/my.h"
> #include "shell.h"
> #include <fcntl.h>
> #include <signal.h>

> void    exec_cmd(char *cmd[], int bg)
> {
>   int   pid;

>   signal(SIGCHLD, waiting);
>   if ((pid = fork()) == -1)
>     {
>       perror("mysh");
>       return;
>     }
>   else if (pid)
>     {
>       if (bg)
>         return;
>       else
>         {
>           setpgid(pid, pid);
>           tcsetpgrp(open("/dev/tty", O_RDONLY), pid)
>           pause();
>           tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())       /* here
> is the mistake, the child die, the father continue
>                                                                    and
> he reveices a SIGTTOU
>                                                                    under
> Linux (it works under NetBSD), and it stops*/
>         }
>     }
>   else
>     {
>       usleep(1);
>       setpgid(getpid(), getpid());
>       if (!bg)
>         {
>           tcsetpgrp(open("/dev/tty", O_RDONLY), getpid())
>         }
>       cmd = redirections(cmd);
>       if (execvp(cmd[0], cmd) == -1)
>         {
>           aff_error("mysh: ");
>           aff_error(cmd[0]);
>           aff_error(": ");
>           aff_error("command not found\n");
>           exit(0);
>         }
>     }
> }

> so if anybody have a solution for this problem....

 
 
 

job control for a shell under linux

Post by Nicolas Delo » Fri, 05 May 2000 04:00:00


Antoine LAURENT a crit :

Quote:> Aren't u in EPITA ?

>         ;-)

yes i am
 
 
 

job control for a shell under linux

Post by Antoine LAUREN » Fri, 05 May 2000 04:00:00


T'es en EPITECH 1 ou INGE 1 ?
 
 
 

1. job control & shells

Summary: how can a process tell if job control is enabled in the
parent process?

The HP-UX 10.20 man page for ex(1) states:
            stop      st[op][!]
            susp

            Suspend the editor job and return to the calling
            shell.  stop and susp are equivalent to suspend.
            susp is the user process control suspend character,
            which is typically the character ^Z (ASCII SUB) (see
            stty(1)).  This command is disabled if the calling
            shell does not support job control or has disabled
            it.

According to their vi(1) man page, the same logic applies to vi, and
it works - if I hit ^z in a vi that was spawned from a shell with
disabled job control, it beeps.  The problem I'm seeing is that the
standard vi clones (vim, nvi, vile, & elvis) do NOT offer the same
functionality - they blindly always attempt to suspend.

    * vim: gives exit code of 129, plus this message:
        Vim: Caught deadly signal HUP
        Vim: Finished.
    * nvi: gives exit code of 129
    * vile: gives exit code of 0
    * elvis -G termcap: hangs entire tty :-(

I want to enhance (at least) vim to beep just like HP's vi, but I
can't figure out how they implemented it.  I thought of checking $-
for the presence of the character 'm', but $- isn't exported, so it's
not visible in a child's environment.  HP also doesn't seem to be
utilizing termios; susp is set to ^z whether or not job control is
enabled.

Any ideas?

The real reason I'm asking: Oracle's sqlplus disables job control
for itself (& all children).  When I tell sqlplus I want to edit the
command currently in its buffer, it fires off vi.  If I use HP's vi, I
get a beep when I hit ^z; if I use one of the clones, the clone goes
into a state of rigor mortis & I have to kill -9 it from a separate
shell.  This gets really irritating really quickly.

J.D. Laub (Laubster) |"I think you're very, very, very, very, very,

2. Killing children

3. Disabling job control for shell scripts

4. What's the best Unix to run Internet Mail

5. No job control in emacs shell, from Slackware Pro 2.0

6. Always on Top in KDE?

7. The shell should handle tty modes along with job control

8. how to install solaris 2.5 x86 to 2.5 gig WD HD

9. 2.1.5 Emacs - no job control in shell?

10. What causes no job control in this shell error

11. get control on bg job of other bash shell

12. Job control in the 'rc' shell.

13. su and "bash: no job control in this shell"