• 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: logout and auto-login
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: logout and auto-login


  • Subject: Re: logout and auto-login
  • From: Jake <email@hidden>
  • Date: Sun, 9 Dec 2001 16:36:00 -0500 (EST)

Finlay:

Thanks for the tip. It worked great. Sorry about starting the quantum
computer vs crypt3 hash war.

// get process by name
void getpidbyname(char *name)
{
int mib[4];
size_t len;
struct kinfo_proc *p;
struct kinfo_proc *cp;
int nentries;
int i;

mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_UID;
mib[3] = getuid();

if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0)
{
NSLog(@"Error calling sysctl");
return;
}
p = (struct kinfo_proc *)malloc(len);
if (sysctl(mib, 4, p, &len, NULL, 0) < 0)
{
NSLog(@"Error calling sysctl");
return;
}

nentries = len / sizeof(struct kinfo_proc);
NSLog(@"%d processes", nentries);

if (nentries > 0)
{
cp = p;
for (i = 0; i < nentries; i++)
{
if (strcmp(cp->kp_proc.p_comm, name) == 0)
{
NSLog(@"%s -> %d", name, cp->kp_proc.p_pid);
break;
}
cp++;
}
}
else
{
NSLog(@"no such process named [%s]", name);
}

free(p);
}

jake



> You can walk the process table programmatically. I used this code to
> check if a pid is running, you could probably adapt it (man 3 sysctl for
> more info) to check for a process by name:
>
> BOOL isPidRunning(int pid) {
> int mib[4];
> size_t len;
> struct kinfo_proc *p;
> int nentries;
> BOOL isRunning;
>
> mib[0] = CTL_KERN;
> mib[1] = KERN_PROC;
> mib[2] = KERN_PROC_PID;
> mib[3] = pid;
>
> if (sysctl(mib, 4, NULL, &len, NULL, 0) < 0) { NSLog(@"Error calling
> sysctl"); return NO; }
> p = (struct kinfo_proc *)malloc(len);
> if (sysctl(mib, 4, p, &len, NULL, 0) < 0) { NSLog(@"Error calling
> sysctl"); return NO; }
>
> nentries = len / sizeof(struct kinfo_proc);
>
> if (nentries > 0) {
> isRunning = YES;
> } else {
> isRunning = NO;
> }
>
> free(p);
> return isRunning;
> }
>
> > as with autologin, the password is does NOT appear to be stored
> > anywhere,
> > no?
>
> of course not. that would be silly, considering everybody can read the
> netinfo db.
>
> -- Finlay


References: 
 >Re: logout and auto-login (From: Finlay Dobbie <email@hidden>)

  • Prev by Date: Preference Pane Localization
  • Next by Date: Re: Sheets in java
  • Previous by thread: Re: logout and auto-login
  • Next by thread: Re: logout and auto-login
  • Index(es):
    • Date
    • Thread