Assume I spawn a process on (csh) command line, like
which creates a process with id 1234. Now, I can suspend/resume that process with
and can query the process state via 'jobs' or 'ps. How can I though query that state programatically (UNIX/POSIX system, no /proc/ available)?
The only call closest to the problem seems waitpid(), which can use WUNTRACED to get notifications on some signals, including SIGSTOP. That seems to work only for processes spawned within the same application - so I would not be able to write a tool which, for the example above, works like
Another option is to do something like
and to grep the output - but ps output is not well standardized (well, it actually is, see ps, but the various implementations do not necessarily adhere to the spec), and also this seems a very cumbersome way to do that. Not to speak of performance...
Any better ideas? The solution ideally should work on MacOS, BSD, Linux, and AIX.
Thanks, Andre.
PS.: yes, I grep'ed the forum: huge amount of related posts, and I may well have missed relevant discussions in the noise. My apologies, and thanks for any pointers...
Last edited by Andre_Merzky; 01-21-2010 at 10:46 AM..
Reason: code tags, please...
1) You create a process responsible for spawing your applications to monitor. That way, you create the parent-child relationship that you need for using waitpaid() with the options WUNTRACED and WCONTINUED.
2) You use the appropriate popen("ps...") code depending on which platform you are running. This can be achieved using old plain #ifdef, or using a strategy pattern.
1) You create a process responsible for spawing your applications to monitor. That way, you create the parent-child relationship that you need for using waitpaid() with the options WUNTRACED and WCONTINUED.
Alas, this is not a viable option in my use case: I have no control over the original parent, nor over spawning process. Well, in those cases where I do have that control, waitpid works nicely of course. The other cases (no control) cause the headache ;-)
Quote:
2) You use the appropriate popen("ps...") code depending on which platform you are running. This can be achieved using old plain #ifdef, or using a strategy pattern.
That is what I do right now, but its ugly, and broken. For example:
So, the process 'sleep' is active in the first case, and suspended in the second. PS reports the same state - I have no means to distinguish. This seems to be valid for all apps which are sleeping or blocking in any way (which are many in our environment, mostly waiting for IO).
So, the process 'sleep' is active in the first case, and suspended in the second. PS reports the same state - I have no means to distinguish. This seems to be valid for all apps which are sleeping or blocking in any way (which are many in our environment, mostly waiting for IO).
weird. From my understanding, this should be in state 'T' (other OSes report this). I am afraid that you have to resort a MAC specific way for this problem... And as a corollary, likely ask a MAC specific Forum. I am afraid, I can't help further (I don't have yet a MAC at home yet. This is one of my future plan )
And as a corollary, likely ask a MAC specific Forum. I am afraid, I can't help further (I don't have yet a MAC at home yet. This is one of my future plan )
Cheers,
Loïc.
Don't get one - its not worth the trouble. Things one a Mac are always *slightly* different than you would expect... :-P
If you are using Mac OS X you can use launchd, and then use launchctl to control it, load it, unload it, etc.
Hi,
your comment finally got me to read the launchd/launchctrl man pages ;-) Interesting, but very much non-portable, and non-API solution to the problem. Also, no suspend/resume AFAICS.
Hi Experts,
I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state.
On doing cat /proc/<pid>wchan showing the "__init_begin" in the output.
Can you please help me here... (6 Replies)
Hi Experts,
I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state.
On doing cat /proc/<pid>wchan showing the "__init_begin" in the output.
Can you please help me here... (1 Reply)
Hi Experts,
I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state.
On doing cat /proc/<pid>wchan showing the "__init_begin" in the output.
Can you please help me here... (0 Replies)
Hello Everyone,
I have a process that should be always running. Unfortunately, this process is getting down almost every 10 minutes. I want to make a script that verify the state of this process: If the process is up, the script shouldn't do nothing and if it's down he should run it.
Can... (3 Replies)
I'm using
"Linux hostname 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 18:40:08 UTC 2009 i686 GNU/Linux"
All the client machines will use Thin-client ,I will use my laptop for working and I will
mount my home directory from server to my laptop.
If I open the firefox in my laptop the... (1 Reply)
Hi Expert,
I am not able to kill certain user process as root. I have tried using:
pkill -u uname
skill KILL -u uname
kill -9 PID
*** I have not using killall yet, since this server has more than 100 users online atm.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND... (1 Reply)
Hi guys,
I'm writing a script in which I have to get file from a remote host by ftp. The problem is that the remote machine could be very slow, not connected or ok. To resolve this problem, I write this:
echo "verbose on" > ftprap.cmd
echo "prompt " >> ftprap.cmd
echo "ascii"... (3 Replies)
Hi all,
I have one requirement,I have two shell programs one is parent and the other one is child . from parent script i need to execute/trigger/call child script as background job. my requirement is after calling child script i want the child process information i.e PID of child weather it is... (8 Replies)