Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

Using readline and signal() to simulate jobs program on Linux

I am writing a simple shell implementation. I am trying to implement a shell functionality that would allow to handle signals such as the CTRL + Z and stop the ongoing process. The process could be later continued using a different functionality. Everything works fine, except that when I am trying to stop the "man ls" process and then later restore it, the text from "man ls" does not come back to the screen.

int m_fg(char **args)
{
    // this just checks if there are any processes on stack that could be "foregrounded"
    if(!pnumber)
       return 1;
    int status;
    // the kill function sends a signal to the child process to be continued
    kill(pvector[pnumber - 1], SIGCONT);
    if(getpid() != pvector[pnumber - 1])
    {
        signal(SIGCHLD, sigstopm);
        waitpid(pvector[pnumber - 1], &status, WUNTRACED);
    }
    if(WIFEXITED(status))
        pnumber--;
    return 1;
}

I think the problem is connected with the man function and the way it is displayed on the screen, since other functions such as htop or vim function properly. Another important thing to mention is that I am using a readline library.

question from:https://stackoverflow.com/questions/65846195/using-readline-and-signal-to-simulate-jobs-program-on-linux

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...