123onetwothree 123onetwothree - 1 year ago 75
Bash Question

print to linux prompt from background process

I was playing on my virtual machine with some exploit learning tricks when i came across this script that was printing to 2 lines and then exit to prompt, and after 10 seconds it printed in my prompt like this :

[!] Wait for the "Done" message (even if you'll get the prompt back).
user@ubuntu:~/tests$ [+] Done! Now run ./exp

How is this possible ? It is clone involved or something like that ?

Answer Source

The program informs you that you should wait for the "Done" message even if you get the prompt back earlier.

This is because some other process is running, detached, in the background.

The process you started has finished, which is why you are getting the prompt back. But it spawned another (background) process, e.g. via fork() or some other mechanic. By the time you get your prompt back, that other process is still running, and you are told to wait for it to finish.

When it does, it prints "Done" to the standard output (stdout) it inherited from its parent -- which is (by default) the same terminal you used to start the initial process.

Not the smoothest design -- the main process could wait for the spawned process to finish before giving you that prompt back, since it is apparently important that other process finishes before you carry on. Perhaps the author didn't know how to do that. ;-)