0

I'm using C++ on linux. I'd like to launch a non blocking process and give the app information using stdin. I don't see a simple way to do so. fork() is the most straightforward solution but the issue is the app may have a password as an argument and by forking I'll have a long lasting process with the password visible through ps.

I'd like to execute the process without blocking and give it information i need via stdin but i'm unsure how (I know how to do it in C# but not C/C++)

  • You may "shadow" password by writing directly to `argv`. – myaut Apr 08 '15 at 08:42
  • Search for, and read about pipes. – Some programmer dude Apr 08 '15 at 08:43
  • What does stdin have to do with program arguments? – JS1 Apr 08 '15 at 08:43
  • 1
    Also in Linux there are ways of setting the process name as displayed by `ps` or similar programs. Search for it. – Some programmer dude Apr 08 '15 at 08:44
  • @JoachimPileborg: is there? From what I hear mysql and other databases recommend not using passwords on command line because `ps` will show it to all users. I'm a little surprised thats possible. I didn't see anything online about it except a little trick by changing argv but argv[1][0]=0 seems to only blank out the first letter. Also IDK why you brought up pipes. I still wouldn't know how to launch nonblocking processes. But now I can use fork so this is a lot easier –  Apr 08 '15 at 09:55
  • @myaut: You mean literally doing `argv[1][0]=0`? I had no idea that works. It only blanked out the first letter but thats ok i'll just find the length using `strlen` –  Apr 08 '15 at 09:58
  • It is better to do `memset(argv[1], 'X', strlen(argv[1]));` – myaut Apr 08 '15 at 09:59
  • If you don't want your program to block waiting for input on stdin, you can use select or poll to check when there's input available, or create a thread dedicated to doing a blocking read independently of the main thread.... Still, I have an uneasy feeling that we have a difference in terminology from what I've ever seen before, and you mean to start a daemon that runs in the background, detached from the terminal? If so, Joachim's suggestion of having it read from a pipe is sensible - then you can write the password into the pipe. – Tony Delroy Apr 08 '15 at 10:12
  • See [this old answer](http://stackoverflow.com/a/17120029/440558), as well as [this `prctl` manual page](http://man7.org/linux/man-pages/man2/prctl.2.html). – Some programmer dude Apr 08 '15 at 11:19

0 Answers0