Killing a background process from a C program

Dave Eisen dkeisen at Gang-of-Four.Stanford.EDU
Fri Jul 20 06:11:16 AEST 1990


In article <1990Jul19.151728.17448 at ncs.dnd.ca> marwood at ncs.dnd.ca (Gordon Marwood) writes:
>
>What I would like to do is start a background process at one point in the
>C program, and at a later time kill it.  Currently I am invoking the
>background process with system("background_process &");, but none of the
>texts that I have available help me to proceed any further.
>

System is not a powerful enough tool for this, it is designed for only
the simplest of process control situations. You'll have to fork and
exec the new process yourself. Fork will create a new process and return
the pid of that process, at some later point use kill (pid, signal_number)
to kill it. For more details, drop me a note or (better still) pick up
a copy of Marc Rochkind's Advanced Unix Programming. (BTW -- even though
it is a UNIX book and not a C book, I think it should be mentioned
in the Frequently Asked Questions posting as an excellent reference for
C programming under UNIX.)

Followups redirected to comp.unix.questions.



--
Dave Eisen                      	    Home: (415) 323-9757
dkeisen at Gang-of-Four.Stanford.EDU           Office: (415) 967-5644
1447 N. Shoreline Blvd.
Mountain View, CA 94043



More information about the Comp.lang.c mailing list