Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1107779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:59:07+00:00 2026-05-17T01:59:07+00:00

I have a custom shell program in which I have included signal.h , unistd.h

  • 0

I have a custom shell program in which I have included signal.h, unistd.h, and stdio.h. I was originally working on this in RedHat Enterprise (not sure exactly what version, but not too old) and I was able to use gcc on my program and it compiled fine and ran fine. Now I moved it over to Ubuntu and gcc is giving me some errors, the first of which is conflicting types for 'getline()'. Some other errors say incompatible implicit declaration of built-in function strlen. I have overridden the functions in question, why was this working in RedHat but not in Ubuntu? Linux is not my thing so please speak plainly. Let me know if you need more error details.

/* define a global input buffer */
#include <signal.h>
#include <unistd.h>
#include <stdio.h>

#define MAXARG 512
#define MAXBUF 512
#define BUFFER_SIZE 50
#define MAX_COMMANDS 10
char buffer [BUFFER_SIZE];
static char *prompt = "MYSHELL>";
static char inpbuf[MAXBUF];
static char *arg[MAXARG+1];
static char tokbuf[2*MAXBUF];
static char *tok = tokbuf;
char history[MAX_COMMANDS][MAXBUF];
int cmd_num;

void getline(void);

void getline() {
int length;

length = read(0, inpbuf, MAXBUF);
if (length == 0) {
    printf("\n");
    exit(0);
}
inpbuf[length] = '\0';

}

void processline() {
char *ptr = inpbuf;
int narg;
for (narg=0;;) {    
    arg[narg] = tok;
    for (; *ptr == ' ' || *ptr == '\t'; ptr++)
        ;
    while(*ptr != ' ' && *ptr != '\t' && *ptr != '\n' && 
          *ptr != '\0' && *ptr != ';' && *ptr != '&') 
        *tok++ = *ptr++;
    *tok++ = '\0';
    if (narg < MAXARG)
        narg++;
    if (*ptr == '\n')
        break;
}
// clear the input buffer
for (ptr = inpbuf; *ptr != '\n'; ptr++)
    *ptr = ' ';
if (narg != 0) {
    arg[narg] = NULL;
}
}

void handle_SIGINT()
{
write(STDOUT_FILENO, buffer, strlen(buffer));
}

int main()
{
    int pid, exitstat, ret;
    struct sigaction handler;
    handler.sa_handler = handle_SIGINT;
    handler.sa_flags = 0;
    sigemptyset(&handler.sa_mask);
    sigaction(SIGINT, &handler, NULL);
    strcpy(buffer, "Caught Control C\n");

    while (1) {
        printf("%s ", prompt);
        fflush(stdout);
        getline();
        processline();
        if ((pid = fork()) < 0){
            fprintf(stderr, "myshell: error\n");
            return (-1);
        }

        if (pid == 0) {
            execvp(*arg, arg);
            fprintf(stderr, "%s\n", *arg);
            exit(127);
        }
        waitpid(pid, &exitstat, 0);
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:59:07+00:00Added an answer on May 17, 2026 at 1:59 am

    Simplest solution would be to rename your getline() function, e.g. to my_getline()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a custom shell script or program that I created myself or
I have implemented my custom ThreadManager which has been working flawlessly during my tests.
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
I have made a custom java program to output a license and am trying
I have a custom shell script that runs each time a user logs in
I have written a custom shell script function, and put in in my .profile
I have a custom application which requires a bunch of things to be set
I'm writing a plug-in for a 3D modeling program. I have a custom class
I have created a BuildProcessTemplate that invokes a custom compiler. This compiler is normally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.