Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programatic tool interaction



If you want to send a kill signal, you need the child process id. popen is a convenience wrapper around pipe creation / setup + fork / exec. If you were to bypass popen (or reimplement your own ~ 15 lines of code) this would be easy as fork returns the child pid to the parent.

From the fork man page:
RETURN VALUES
Upon successful completion, fork() returns a value of 0 to the child
process and returns the process ID of the child process to the parent
process. Otherwise, a value of -1 is returned to the parent process, no
child process is created, and the global variable errno is set to indi-
cate the error.


Hope it helps.


On Dec 22, 2005, at 2:58 PM, Caius wrote:


Hi

I have a related question.

I am actually using popen to run some shell scripts from within an application. However sometimes these scripts hang and I would like to be able to kill the script after some amount of time. Otherwize, when I kill the parent application the script is still running and therefore the resources (sockets etc..) associated with the application dont get closed.

Is there some way of sending a kill signal to a processes started with popen()? pclose is no good as it waits for thhe child to exit.

Thanks
Caius

On 21 Dec 2005, at 12:32, Brian J. Landsberger wrote:

Kevin,

You may be able to use popen for this, Stevens covers this in sections 14.3 and 14.4 of Advanced Programming in the UNIX Environment (first revision). I suggest reading through Chapter 14 though.

Thanks,

Brian J. Landsberger
email@hidden
Cell: 206.658.5819



On Dec 21, 2005, at 12:08 PM, Kevin Packard wrote:

Please forgive me if this is not the appropriate list, but I've not been unable to google the answer, or find it in Apple's dev pages.

Is there any way to programatically interact with a UNIX tool from a Carbon app? sysctl() gives me a one-shot run, but I'd like to launch a tool, create some sort of a pipe to it, write to its stdin, and read from its stdout.

Can someone please point me to a method to do this (or tell me I'm insane)?

thanks,
--
Kevin Packard

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/brian% 40landsberger.com


This email sent to email@hidden


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/howcroft% 40hep.phy.cam.ac.uk


This email sent to email@hidden

--
Caius Howcroft
Mobile (UK): +44 779 203 0046
Mobile (US): +1   626 487 1202
Skype:  caiush

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/unix-porting/ldm% 40thorgal.homelinux.org


This email sent to email@hidden

-- Laurent


_______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/email@hidden

This email sent to email@hidden
References: 
 >programatic tool interaction (From: Kevin Packard <email@hidden>)
 >Re: programatic tool interaction (From: "Brian J. Landsberger" <email@hidden>)
 >Re: programatic tool interaction (From: Caius <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.