0

I am trying to write a program , which does a fork and exec a child process and executes it in the back ground .

One approach I would see is to redirect the output to /dev/NULL file and come back to my main program . Any other ideas ?

Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
Srikanth
  • 447
  • 2
  • 8
  • 1
    When asking questions, please provide a specific example of what you're trying to achieve and also what you've currently done. In its current state, your question can't really be answered and may be closed. To learn more about asking great questions, see How to Ask- http://stackoverflow.com/questions/how-to-ask. – Damodaran Nov 22 '13 at 07:06
  • I am creating my own shell which mimics the behavior of linux shells . Here i want to implement '&' - which runs the process in the background. Hope it gives better insight to my problem – Srikanth Nov 22 '13 at 07:08
  • @Srikanth: I would suggest editing that into your question, and reconciling it with what's there. (Most shells do not redirect output with `&`.) – Thanatos Nov 22 '13 at 07:15
  • @Srikanth You can look this website:http://stackoverflow.com/questions/116701/how-can-a-c-c-program-put-itself-into-background – BlackMamba Nov 22 '13 at 07:36
  • @Srikanth - I can't figure out what you want. Please edit your question. – Vishal R Nov 22 '13 at 08:44
  • I am creating my own shell which mimics the behavior of linux shells . Here i want to implement '&' - which runs the process in the background. Hope it gives better insight to my problem – Srikanth Nov 22 '13 at 08:48

1 Answers1

0

After a process is started, shell has no more control on process file descriptors so you can not silence it by a shell command i.e. terminal has its stdin, stdout and stderr bound to the terminal and you cannot do anything about it without re-gaining control over that terminal.

There is a tool called retty how you can use it can be seen at this link retty this tool is used to attach processes running on terminals

Beside you can also use the built in disown command to disown the process which will prevent from sending a SIGHUP signal to the program when the shell exits

This link can be helpful Link to a similar problem

Community
  • 1
  • 1
Vinay Shukla
  • 1,818
  • 13
  • 41
  • Thanks , But i am just curios to know how a "fg " works when you say shell has no more control on process ? – Srikanth Nov 22 '13 at 08:35
  • Please read properly @Srikanth i said process file descriptors. while `bg fg kill` are control commands which no one can stop you from using – Vinay Shukla Nov 22 '13 at 08:52