• 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: socko2: kill process by name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: socko2: kill process by name


  • Subject: Re: socko2: kill process by name
  • From: Mike Davis <email@hidden>
  • Date: Thu, 7 Feb 2002 12:21:16 -0500

You can walk the process list using UNIX calls (see "man 3 sysctl" and "man 2 kill").

int mib[ 3 ] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
size_t length;
struct kinfo_proc *theProcessInfoData;
struct kinfo_proc *theProcessInfo;
NSString *theProcessName;
pid_t theProcessID;

if( sysctl( mib, 3, NULL, &length, NULL, 0 ) == -1 ) return nil;

theProcessInfoData = (struct kinfo_proc*)malloc( length );

if( sysctl( mib, 3, theProcessInfoData, &length, NULL, 0 ) != -1 ) {
theProcessInfo = theProcessInfoData;

do {
theProcessName = [NSString stringWithCString:theProcessInfo -> kp_proc.p_comm];
theProcessID = theProcessInfo -> kp_proc.p_pid;

fprintf( stderr, "%s = %d\n", [theProcessName cString], (int)theProcessID );

theProcessInfo ++;
} while( (size_t)theProcessInfo < (size_t)theProcessInfoData + length );
}

free( (void*)theProcessInfoData );


---
Only Mortal, the internet game server browser for MacOS X.
Visit: http://homepage.mac.com/only_mortal/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Mixing Carbon & Cocoa?
  • Next by Date: NSPopUpButton is too smart for it's own good
  • Previous by thread: Re: socko2: kill process by name
  • Next by thread: Multiple nibs
  • Index(es):
    • Date
    • Thread