• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Who's launching me?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Who's launching me?


  • Subject: Re: Who's launching me?
  • From: Michael Rothwell <email@hidden>
  • Date: Sun, 12 Feb 2006 18:10:51 -0500

The function getppid() will return the process ID (pid) of your program's parent process.

From Terminal, or an NSTask, you can use `ps` to get the name of a process based on its pid. Examples:

$ ps -p 190
PID TT STAT TIME COMMAND
190 ?? S 27:14.32 /System/Library/CoreServices/Dock.app/ Contents/MacOS/Dock -psn_0_524289


$ ps -p190 -c
  PID  TT  STAT      TIME COMMAND
  190  ??  S     27:14.32 Dock

You could use kvm_getargv()/kvm_getprocs() to get information about the parent process. From the kvm man page:

kvm_getargv() returns a null-terminated argument vector that corresponds
to the command line arguments passed to process indicated by p. Most
likely, these arguments correspond to the values passed to exec (3) on
process creation. This information is, however, deliberately under con-
trol of the process itself. Note that the original command name can be
found, unaltered, in the p_comm field of the process structure returned
by kvm_getprocs().


-M

On Feb 12, 2006, at 5:09 PM, Paul J. Lucas wrote:

	Is there any way for an application to know what other
	application launched it?

	I want to be able to distinguish between being launched via the
	Finder and launched as an "external editor" for some other
	application, e.g. iPhoto.

	- Paul
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

-- Michael Rothwell email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Who's launching me? (From: "Paul J. Lucas" <email@hidden>)

  • Prev by Date: Re: Core Data, transient ivars and undo
  • Next by Date: Re: NSMenu on click of a button
  • Previous by thread: Re: Who's launching me?
  • Next by thread: Re: Who's launching me?
  • Index(es):
    • Date
    • Thread