1

I'm trying to build a simple shell by C in windows, my platform not good so I searched and begin with some code like below:

shell_terminal = STDIN_FILENO;
shell_is_interactive = isatty (shell_terminal);
if (shell_is_interactive)
{
    /* Loop until we are in the foreground.  */
    while (tcgetpgrp (shell_terminal) != (shell_pgid = getpgrp ()))
    kill (- shell_pgid, SIGTTIN);

    /* Ignore interactive and job-control signals.  */
    signal (SIGINT, SIG_IGN);
    signal (SIGQUIT, SIG_IGN);
    signal (SIGTSTP, SIG_IGN);
    signal (SIGTTIN, SIG_IGN);
    signal (SIGTTOU, SIG_IGN);
    signal (SIGCHLD, SIG_IGN);

    /* Put ourselves in our own process group.  */
    shell_pgid = getpid ();
    if (setpgid (shell_pgid, shell_pgid) < 0)
    {
    perror ("Couldn't put the shell in its own process group");
    exit (1);
    }

    /* Grab control of the terminal.  */
    tcsetpgrp (shell_terminal, shell_pgid);

    /* Save default terminal attributes for shell.  */
    tcgetattr (shell_terminal, &shell_tmodes);
}

But I had somes bug:

[Error] 'tcgetpgrp' was not declared in this scope
[Error] 'getpgrp' was not declared in this scope
[Error] 'SIGTTIN' was not declared in this scope
[Error] 'kill' was not declared in this scope
...

I think has problem with my environment or miss some library. What's my problem? Thanks!

Thangnv
  • 805
  • 3
  • 11
  • 22

1 Answers1

0

Because, tcgetpgrp function, is not defined by ISO C standard, which must be supported by all operation systems, rather it is defined by IEEE POSIX standard, which is most commonly supported by Unix system enviroments.

For eg:

<unistd.h>, which is required to compile this program, is header file defined by POSIX standard, not ISO C Standard.

Either upgrade to POSIX compatible system, or use Windows API, which provide similar set of services for windows platform.

mohit
  • 5,696
  • 3
  • 24
  • 37
  • So, what can i do it in windows? – Thangnv Aug 03 '13 at 09:38
  • If you want to use Posix defined functions, I recommend you to upgrade to any unix or linux platform. – mohit Aug 03 '13 at 09:40
  • So hard for me, i don't want work with virtual machine and don't want install linux. I'm trying to build a simple shell, do you have some suggestion for me ? my shell must have some function to call windows API. Tks! – Thangnv Aug 03 '13 at 09:44
  • That was the same thing I said 2 years before. And now I really enjoy working in Linux. You can start with [ubuntu](http://www.ubuntu.com/), it's great for beginners. Check out this [question](http://stackoverflow.com/questions/2270527/how-to-code-a-new-windows-shell), if you still insist on building a shell in windows. – mohit Aug 03 '13 at 09:48