Process count problem in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process count problem in script
# 8  
Old 07-04-2013
Quote:
Originally Posted by RudiC
Funny enough - I placed a tee into the pipe, and - there are two processes! See:
Code:
check=$(ps -ef|tee xx|grep -c "[s][h] -x abc.sh")
less xx
...
userx   6061  4983  0 17:44 pts/2    00:00:00 bash -x abc.sh
userx   6062  6061  0 17:44 pts/2    00:00:00 bash -x abc.sh

one being an immediate subprocess of the other. Strange!
I don't find it strange at all. To execute the command substitution, the shell forks, creating a copy of itself. The new process has the same argv as its parent.

Regards,
Alister
# 9  
Old 07-04-2013
I thought about the fork to execute the command substitution, but shouldn't the exec thereafter set the command name, i.e. argv[0]?
# 10  
Old 07-04-2013
There's another layer of forking before any exec is necessary. The parent shell forks to create a subshell for the command substitution. This child subshell then itself forks several times to create each pipeline component. Only these grandchildren shell processes need to exec.

Regards,
Alister
# 11  
Old 07-04-2013
OK, thanks, got you. But, how then are rbatte1's results for RHEL and HPUX possible, posted in #5?
# 12  
Old 07-04-2013
I can't say for certain without more information.

Perhaps the subshell is not forking a process for the final command in the pipeline, but, exec'ing directly. Both this behavior and the behavior described in my previous post are POSIX-compliant. From the end of Shell Command Language :: Section 2.12 :
Quote:
Command substitution, commands that are grouped with parentheses, and asynchronous lists shall be executed in a subshell environment. Additionally, each command of a multi-command pipeline is in a subshell environment; as an extension, however, any or all commands in a pipeline may be executed in the current environment.
It's also possible (though, I suspect, less likely) that the subshell is manipulating its argv and the ps implementation does not obtain its info from saved kernel space values.

And, finally, there's also the possibility of PEBKAC (no offense intended, rbatte1 Smilie).

Regards,
Alister

Last edited by alister; 07-04-2013 at 03:16 PM..
# 13  
Old 07-05-2013
No offence taken, mainly because I don't recognise the acronym. Smilie Is it a little like PICNIC (Problem In Chair Not In Computer) Smilie

I won't be offended anyway, I am here to learn more than anything. Smilie



Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Telnet and get process count

Hi guys, I'm writing a script on a Solaris 10 server (server A) that needs to telnet 2 servers (server B & server C) and get a certain process count from these 2 servers. Then on server A, I check if both counts are greater than 17, I do a sendmail to concerned people. For the telnet part,... (7 Replies)
Discussion started by: frum
7 Replies

2. Shell Programming and Scripting

Process a file for line count using for loop in awk

Hi, I have a file with contents So what I have to do is In short, break the file after every 6 lines and then truncate new line to tab for these 6 lines. I am not able to execute the for loop in awk properly. The idea is something like this: less file| awk '{for .... {if ((nr>=1)... (7 Replies)
Discussion started by: rossi
7 Replies

3. AIX

Check process count

Hi, We have scheduled few jobs/scripts in cron and it runs on daily basis at a specified time. We have a cron jobs has various parameters for main scripts like /home/test/mainscript.ksh main_param when the above jobs triggers, mainscript.ksh has below code and it refers ... (3 Replies)
Discussion started by: Selva_2507
3 Replies

4. Shell Programming and Scripting

Problem with a script for checking the state of a process

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)
Discussion started by: adilyos
3 Replies

5. Shell Programming and Scripting

Using backspace in echo to show process count

i have something like this tablesName="abc def hij akn ... etc etc" count=0 for i in $tablesName do echo -en "\b\b\b\b\b\b\b\b\b\b\b\b\bTableCount: $count" count=`expr $count + 1` done the above is just a description wha i need is when the loop executes the... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. UNIX for Dummies Questions & Answers

Thread count for a process id

Hi, I want to know a command/program to get thread count for a process id in unix box. Please help me in this regard. (1 Reply)
Discussion started by: manaac
1 Replies

7. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

8. Shell Programming and Scripting

facing problem in starting a process in background using shell script.

hey all, i am working on sun solaris machine and i want to start a process in background using shell script (actually i wanna start tomcat server using shell script). please dont tell me that append a & at last because this is not working in the shell script. i have also used nohup and... (8 Replies)
Discussion started by: dtomar
8 Replies

9. HP-UX

how to see the threads count of a process in hp unix?

hi,all: how to see the threads count of a process in hp unix? thanks (2 Replies)
Discussion started by: bugbugbug
2 Replies

10. Programming

Count Number Of Threads in a Process

I am trying to find out that how many number of threads are currently running or in any other state which is created by POSIX standard in a process. First I have defined a variable called proc_var of type proc defined in sys/proc.h.Next I open up the dir /proc and per directory wise I do an ioctl... (7 Replies)
Discussion started by: S.P.Prasad
7 Replies
Login or Register to Ask a Question