Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 13 of 13
I'm really surprised no one has thought of this yet. Really, there has to be a script or something like it out there. This idea seems far too common to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Just Joined!
    Join Date
    Apr 2009
    Posts
    5

    I'm really surprised no one has thought of this yet. Really, there has to be a script or something like it out there. This idea seems far too common to not have been thought up of before. IMO this function really should be apart of the standard linux package, considering it is very convenient, and if windows has it linux should too.

    I don't think this has anything to do with the terminal gui app, since the terminal emulator is just going to pass the key stroke to the tty session anyway, unless that key command is hot keyed to the app. After all, when you're running a process, be that a c program or whatever, suspend(^z) and terminate(^c) still function.

    I think this has something to do with the tty driver. A function that cycled through the command history would need an event handler that signalled when a process is in WCHAN read_c and STAT S+, then it would have to look up a list containing the command history of a specific process; and of course be bounded to the arrow keys(^[[A,^[[B).

    So, does anyone know of any sites with information on the tty driver, specifically one that has information on how to add custom functions. This has to be possible since I know with stty you can change the special character bindings for suspend, terminate, etc.

    -Alphonse

  2. #12
    Just Joined!
    Join Date
    May 2009
    Posts
    1
    the shell program handles this. Here is how it generally works:

    When you run a program, bash calls an "exec" function, which forks itself (bash), and replaces it's own stack and memory with the program you're running

    from the man pages:
    "execv replaces the currently executing program with a newly loaded program image. This occurs within one process; the process id is unchanged. "

    So, in order to do that, you'd have to have it in your program's functionality which would be a complete hassle, especially with cross-process programming. not as easy as it sounds! When you run something, bash is no longer in control. You'd have to install a signal handler for up/down arrow, and get a list of the previously used commands (from bash) and output them accordingly. Bash is a pretty robust program, this would be hard to do.

    An easy solution would be to instead of using stdin input functions (cin, scanf), make it use command line input instead so you can easily run a program and just change the cmd line arguments each time with the up arrow.

  3. #13
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,558
    Quote Originally Posted by warMen View Post
    the shell program handles this. Here is how it generally works:

    When you run a program, bash calls an "exec" function, which forks itself (bash), and replaces it's own stack and memory with the program you're running

    from the man pages:
    "execv replaces the currently executing program with a newly loaded program image. This occurs within one process; the process id is unchanged. "

    So, in order to do that, you'd have to have it in your program's functionality which would be a complete hassle, especially with cross-process programming. not as easy as it sounds! When you run something, bash is no longer in control. You'd have to install a signal handler for up/down arrow, and get a list of the previously used commands (from bash) and output them accordingly. Bash is a pretty robust program, this would be hard to do.

    An easy solution would be to instead of using stdin input functions (cin, scanf), make it use command line input instead so you can easily run a program and just change the cmd line arguments each time with the up arrow.
    Exactly! The shell does a fork/exec which is as old as Unix. Also, if it is executed in the background, then it has to detach itself from the forking process so it won't be killed if the parent process goes away (sets SIGHUP on children). The nohup command will also deal with that for applications that don't detach themselves properly from the parent process, so you can start them up in the background, and then shut down the shell - the nohup'd processes will keep running.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •