LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-31-2008, 08:46 AM   #1
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Rep: Reputation: 15
number of processes, how to get notified on a change


Hi,

I was wondering whether there is a variable for storing current number of processes on the system.

Also, how can I get notified when a new process enters the system.

Thanks for any input...
 
Old 07-31-2008, 09:55 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
What sort of system is it (desktop/embedded/etc)?
 
Old 07-31-2008, 10:00 AM   #3
allez
Member
 
Registered: Jul 2008
Location: Russia/Siberia/Krasnoyarsk
Distribution: SuSE, CentOS, FreeBSD
Posts: 77

Rep: Reputation: 21
Quote:
I was wondering whether there is a variable for storing current number of processes on the system.
There is no such a variable. You may learn how many processes in your system are working, by this command: ps axh | wc -l. Of course, you can assign its output to a variable. :-)

Quote:
Also, how can I get notified when a new process enters the system.
Hmm, may I ask why do you want this? Working system is not somethig static, there are a number of processes (even on a home desktop, not only server) which may terminate, spawn child processes, run external commands/utilities etc. Monitoring of these activities can be a liittle bit annoying. ;-)

P. S. Oops, didn't notice that this is "Non-*NIX Forums > Programming". Sorry, mea culpa. :-) This post can be deleted.

Last edited by allez; 07-31-2008 at 10:11 AM. Reason: An erroneous post
 
Old 07-31-2008, 10:47 AM   #4
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
What tools are you willing to use? Do you want to run a script every five minutes via cron? Do you want to write a daemon? Do you want to modify fork?
 
Old 07-31-2008, 07:30 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
allez makes a good pt, if this is *nix, or (I believe) almost any OS. The num of processes is usually highly dynamic. Embedded systems would be a different kettle of fish
 
Old 08-01-2008, 02:55 AM   #6
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Again, depending on what you hope to achieve, using inotify on /proc might be an option.
 
Old 08-04-2008, 08:54 AM   #7
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
Hey thanks for the input...
 
Old 08-13-2008, 09:35 AM   #8
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
Hi, I am not able to get notified when a new process enters the system. Could any body guide me on how can this be done. Inotify does not work on /proc. I don't want to run a daemon which goes through the list in /proc every few milliseconds to know that new process has come.

Even if I try to see when the fork system call is made, its quite heavy as every time a system call is made, we have to check whether the system call is fork..

It does not matter for me if the number of processes is huge. I wont do much processing when I get notified about the entry of the process. So number of processes is not an issue.

Please comment. I am stuck at this point...

Thanks...
 
Old 08-25-2008, 10:57 AM   #9
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
Hi,

Could anybody please guide me how I could do this. This is required for my term project and I am almost stuck here from 10 days... I know that there are people here who can guide me..

Thanks for any input...
 
Old 08-25-2008, 11:06 AM   #10
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by linuxdoniv View Post
Hi,

Could anybody please guide me how I could do this. This is required for my term project and I am almost stuck here from 10 days... I know that there are people here who can guide me..

Thanks for any input...
Two things:

1. You did not answer the question which I asked you after your original post. When someone responds with a request for more information, it is good manners to respond to their request.

2. We are not here to do your homework. See the LQ rules. If you can show that you have taken some steps toward finding a solution, and need guidance about what direction to take, most people (including me) are happy to help, but don't expect us to provide you with solutions to your homework questions.

Did you try anything yet? If so, what?
 
Old 09-01-2008, 09:05 AM   #11
linuxdoniv
Member
 
Registered: Mar 2008
Posts: 63

Original Poster
Rep: Reputation: 15
Sorry matthewg42, Sorry for the late reply.

The system is embedded one (N810).

I have not been able to do much as there is nothing else I can do except getting notified about the entry of a process.

I thought going through the entries in /proc very often would result in huge overhead as this has to be done very frequently.( may be 100 millisecods ?...)

So I have been thinking that getting notified about process entry is the only solution.

I am not asking anybody to do my homework. I just wanted to say that I have been helpless is solving the problem for a long time.

Thanks for any guidance in this regard,
 
Old 09-03-2008, 03:13 PM   #12
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i think you can loop and sleep every 100 ms and do a ps | wc -l and if it changes do what you need to do.
 
Old 09-04-2008, 01:16 AM   #13
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
There is no such a variable. You may learn how many processes in your system are working, by this command: ps axh | wc -l. Of course, you can assign its output to a variable. :-)
Running this command will generate two processes.

Processes may come and go at the rate of several per second. Being notified about each of these seems like a good way to suck the CPU and bury the I/O channels.
 
Old 09-04-2008, 01:24 AM   #14
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
If you really need to do this, you need to create a process that doesn't end, and you probably should do it in C or C++. Easiest way would be to make it sleep for a set time then execute a loop. When it checks for new processes, it should do this without spawning any other processes. To do this, you need to learn about the task structure and how to walk it, because this is where the system stores its task information. Basically, each time through the loop, you walk the entire task list via the links in the task structure, looking for whatever information interests you. You also would presumably count the entries in the list.
 
Old 09-04-2008, 02:43 AM   #15
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Can you explain what purpose there is to being notified about process creation? This seems a rather peculiar quest.

The correct and most efficient way to do this would be to modify the kernel source, adding the necessary code to the code that implements execve(2). Any other polling method in userspace will be unreliable, and very expensive.

For a standard user-space implementation, with notification via signals, there is no guaranty that you will get "notified" on every single execve(2) call. You may get notified only once for more than one new process exec'd. You'd need to implement a user-space kernel daemon.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
notified of ip address change taltman Programming 7 07-28-2007 02:36 AM
monitor processes to be notified when a new process is started? cfh Programming 2 10-03-2005 07:07 PM
Number of Mysql processes ugob Linux - Software 0 12-05-2003 01:33 PM
how to change number of running processes rsc Linux - Newbie 2 03-14-2002 05:23 PM
how to change number of default processes rsc Linux - Networking 2 03-13-2002 01:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration