[SOLVED] system call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

[SOLVED] system call

Post by sharyn »

I am on a Mac OS X server and I am trying to one of two things... if I can get either one to work I'd be happy.

First, I'm trying to do a system call to get the running processes. Doing a "ps -cx" in PHP give me a different set of processes than when I type it into the terminal window. I need the set that is returned in the terminal window. I also need to redirect it into a file so I can see if the process I want is running since I don't think I can check the output of the system call in the PHP script.

Second, if I can't get the proper set of processes back using a php system call I can run a simple C program that can do it, but I can't seem to call the C program from PHP.

Here is the code I've testing with :

Code: Select all

system("ps -cx");  echo "<br>";
system("ps -cx > SystemCheckFile.txt"); 
system(/User/administrator/C\ Apps/SystemCall/SystemCall");
The first one echos out the processes but all I get back is a series of httpd processes.

The second one is supposed to redirect the output to the fiel SystemCheckFile.txt, but I can't find it anywhere on my computer which leads me to believe that the file is not getting creatied.

The third one calls a C program that does the same thing as the second call except when I run the program on it's own, I get all the processes that I am expecting, such as Netscape, Finder, Dreamweaver..etc...

If anyone has a suggestion, I am willing to listen :)

- sharyn
Last edited by sharyn on Thu Oct 28, 2004 3:41 pm, edited 1 time in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Trying running:

Code: Select all

ps -aux
And you should get every process unless the kernal is set to only show users their own processes. ps is im sure a C program itself already so i certainly wouldnt run a second C program to run the first.
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post by sharyn »

kettle_drum,

Thanks, but on the Mac OS X, ps -cx is exactly what I need. :)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Well your not going to get anybodys but your own processes if you dont run the command with -a in it as that lists all processes:

Code: Select all

Bluebird:~/Sites greybird$ ps -cx
  PID  TT  STAT      TIME COMMAND
  171  ??  Ss    22:37.67 WindowServer
  175  ??  Ss     0:30.07 ATSServer
  181  ??  Ss     0:04.51 loginwindow
  331  ??  Ss     0:00.95 pbs
  336  ??  S      0:17.12 Dock
  365  ??  S     12:42.72 SystemUIServer
  367  ??  S      0:12.21 Finder
  407  ??  S      0:01.41 iCalAlarmScheduler
  408  ??  S      0:00.27 Microsoft AU Daemon
  409  ??  S      0:00.68 GrowlHelperApp
  411  ??  S      3:19.02 UniversalAccess
  423  ??  S      0:01.34 AppleSpell
  441  ??  S      0:48.13 Mail
  442  ??  S      0:36.74 iChat
  460  ??  Ss     0:08.56 iChatAgent
  586  ??  S    103:16.91 Safari
  669  ??  S      2:59.32 iTunes
  695  ??  S      0:07.21 Terminal
  697 std  S      0:00.08 -bash
Bluebird:~/Sites greybird$ ps -acx
  PID  TT  STAT      TIME COMMAND
    1  ??  Ss     0:00.03 init
    2  ??  Ss     0:00.84 mach_init
   78  ??  Ss     0:01.08 syslogd
   84  ??  Ss     0:03.59 kextd
   86  ??  Ss     2:23.78 configd
   87  ??  Ss     0:00.55 diskarbitrationd
   92  ??  Ss     0:02.42 notifyd
  117  ??  Ss     0:06.42 netinfod
  119  ??  Ss     0:48.47 update
  125  ??  Ss     0:00.07 dynamic_pager
  149  ??  Ss     0:02.43 coreservicesd
  150  ??  Ss     0:01.37 distnoted
  155  ??  Ss     0:03.14 mDNSResponder
  156  ??  Ss     0:00.01 KernelEventAgent
  166  ??  Ss     0:01.34 SecurityServer
  168  ??  Ss     0:00.56 cron
  171  ??  Ss    22:39.77 WindowServer
  174  ??  S      0:00.03 ioupsd
  175  ??  Ss     0:30.07 ATSServer
  181  ??  Ss     0:04.51 loginwindow
  185  ??  Ss     0:01.67 DirectoryService
  216  ??  Ss     0:00.02 crashreporterd
  237  ??  Ss     0:12.19 cupsd
  244  ??  S      0:00.05 sh
  266  ??  R      7:01.85 mysqld
  326  ??  Ss     0:00.25 master
  327  ??  Ss     0:10.31 httpd
  328  ??  S      0:00.96 httpd
  331  ??  Ss     0:00.95 pbs
  336  ??  S      0:17.21 Dock
  365  ??  S     12:42.97 SystemUIServer
  367  ??  S      0:12.21 Finder
  368  ??  Ss     0:08.96 ntpd
  386  ??  Ss     0:00.01 nfsiod
  395  ??  Ss     0:00.01 rpc.lockd
  398  ??  Ss     0:00.12 automount
  402  ??  Ss     0:00.06 automount
  407  ??  S      0:01.41 iCalAlarmScheduler
  408  ??  S      0:00.27 Microsoft AU Daemon
  409  ??  S      0:00.68 GrowlHelperApp
  411  ??  S      3:19.18 UniversalAccess
  423  ??  S      0:01.34 AppleSpell
  441  ??  S      0:48.13 Mail
  442  ??  S      0:36.74 iChat
  460  ??  Ss     0:08.56 iChatAgent
  546  ??  Ss     0:18.89 lookupd
  586  ??  S    103:21.73 Safari
  669  ??  S      2:59.46 iTunes
  679  ??  S      0:00.94 httpd
  680  ??  S      0:00.63 httpd
  681  ??  S      0:00.96 httpd
  682  ??  S      0:00.49 httpd
  695  ??  S      0:13.59 Terminal
  696 std  Ss     0:00.09 login
  697 std  S      0:00.09 -bash
  737 std  R+     0:00.00 ps
Bluebird:~/Sites greybird$
You only get the httpd processes as that is the user who is executing the command.
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

* SOLVED *

Post by sharyn »

Kettle_drum,

You are right, I guess I missed my process the first time I tried "ps -aux" because there was way too much output. In the end, I got my problem fixed :

Code: Select all

do &#123;
  $PNG_running = system("ps -acux | grep PNG");
&#125; while (strlen($PNG-running) > 0)
when the PNG process stops running, I can display my PNG file :D


Thanks a million !
Last edited by sharyn on Wed Oct 27, 2004 3:43 pm, edited 1 time in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Since your a fellow mac user....you see the keynote on Tuesday?!? Gotta get me an iPod Photo.
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post by sharyn »

Keynote? No, where is it? can you either post the link or PM me with it? I want an iPod :D :D
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Post Reply