Process output in different layout


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process output in different layout
# 1  
Old 09-07-2016
Process output in different layout

I was looking for samething more compact than this:

Code:
$: a=`ls`
$: declare -i num=0
$: for x in $a; do num=$num+1;  echo "$num ..... $x"; echo "$num       $x">fl_tmp; done

And jump in my mind to use parallel but look at the performance:

Code:
$: a=`ls`
$: time for n in {1..10}; do parallel 'printf "%i      %s\n" {#} {} > fl_tmp; echo {#}.....{}' ::: $a; done

real	0m7.120s
user	0m4.260s
sys	0m1.680s

$: time for n in {1..10}; do declare -i num=0; for x in $a; do num=$num+1;  echo "$num ..... $x"; echo "$num       $x">fl_tmp; done; done

real	0m0.748s
user	0m0.060s
sys	0m0.100s

Maybee it was expectable that parallel in this occasion could not give the best performance, but the result is really depressive, isn't it!

So if you got a compact and clever way to do that let me know
or if you understand what is so wrong with parallel let me know as well!
# 2  
Old 09-07-2016
Quote:
Originally Posted by flaviofachin
Maybee it was expectable that parallel in this occasion could not give the best performance, but the result is really depressive, isn't it!
Sticking 'parallel' in front of a line doesn't make it go faster. You haven't made the loop run in parallel -- you're running 'parallel' 10 times.

I don't think you can parallelize this much, there's not much there, there's lots of I/O you don't want to overlap each other, the order of output might get mixed up, 'parallel' is not a shell keyword but launches whole new entire shells, and each loop depends on the last anyway.
# 3  
Old 09-07-2016
Look my code dose preciselly what I intended to do:
The repetition of 10 time is for testing porpouse.

It was just an experiment.
It was something like a tee command where each argument was process in parallel.
The command take each argument in a$, making a new job that process it in two different layout.

Any good idea for obtaing (maybee using "xargs" or something) a quality and compact code, to use instead of the first option?

For me it was an interesting experiment. I belived that initialising new process was not so much expensive in time.

Last edited by flaviofachin; 09-07-2016 at 01:57 PM..
# 4  
Old 09-07-2016
There's a lot involved in splitting off processes, yes. Allocating and destroying lots of memory. Looking up paths, opening files, parsing libraries. Stopping and starting the "universe" (program context) multiple times. If you create a process, it's a good idea to let it do as much work as possible before killing it or getting in its way.

xargs isn't terribly useful here, again, it ends up creating processes so suffers the same drawback. It's nice for when you need to create processes, or can bundle multiple calls into one big call.

For high compactness, fewer externals, and the ability to handle spaces in filenames:
Code:
N=0 ; for x in * ; do printf "%d %s\n" $((++N)) "$x" ; done

To bundle it all in one enormous printf, which might be more i/o efficient:

Code:
s=""
n=0
for x in * ; do  s="$s $x $((++n))" ; done

for n in {1..10} ; do printf "%d %s\n" $s ; done


Last edited by Corona688; 09-07-2016 at 03:41 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash process output analysis

Looking to create a script to listen to each output from a task while it is running and launch a function if a specific error message is found at any point and if not to continue uninterrupted. #!/bin/bash read checker <<< $(reaver -i mon0 -b 'target bssid' -vv) if ; then function elif... (1 Reply)
Discussion started by: 3therk1ll
1 Replies

2. Shell Programming and Scripting

Output when killing a background process

I played a bit around with the Terminal and I observed something. When I start and kill a background process, there is some kind of output. After I invoked the command to start the process the first message " 13063" is directly displayed. However, after killing the process, the second message "+... (3 Replies)
Discussion started by: Chuck Morris
3 Replies

3. UNIX for Dummies Questions & Answers

Seeing output of background process

I'm pretty sure I had the answer to this months ago and have misplaced it. Needless to say I will bookmark it this time. I have a background process that's been running way longer than usual. It doesn't output anything to a file, so I can't 'tail -f' it. Is there a command that will enable me to... (2 Replies)
Discussion started by: dheian
2 Replies

4. Shell Programming and Scripting

Appending process output into a file

Hello Friends, I'm trying to save process status of root user sorting by CPU usage. However i couldnt save the continuous, standard outputs into a file. Do you have any idea to do it? prstat -u root -a -s cpu | sed -e '/^$/d;/sleep/d;/Total/d' >> stat.txt >ls -l stat.txt -rw-r--r-- 1... (1 Reply)
Discussion started by: EAGL€
1 Replies

5. Shell Programming and Scripting

Write process output to a file

When I run <ls -l> to get a list of all the files, I want the displayed result to be written to a text file. Is there a way to do that? (1 Reply)
Discussion started by: kn.naresh
1 Replies

6. Shell Programming and Scripting

Redirect bg process output to within the script

Hi, I have a process running in the background, which throws up some output to the terminal when I run my script. How can I read this output from my script? Thank you. (5 Replies)
Discussion started by: Theju
5 Replies

7. Shell Programming and Scripting

Using ls output for other process

Hello, Just to set the tone: I am a complete UNIX noob (i guess you see that excuse popping up frequently here but anyhow) Now here's my bloody simple problem which needs to be quite urgently resolved: I have a number of files in a directory, for which the ones, relevant for executing a... (3 Replies)
Discussion started by: eich
3 Replies

8. Shell Programming and Scripting

Can ps just output the process name?

I'm trying to get the ps command to just output the name of the processes currently running, but I can't figure out a way to do it. I'm using OSX, so some UNIX features are crippled. Is there any way for me to do this? Thanks, Black Leopard (4 Replies)
Discussion started by: blckleprd
4 Replies

9. UNIX for Dummies Questions & Answers

Opening output file while still in process

Dear guru, Say I have a long process that is executed in this way: $ nohup perl mycode.pl > output.txt & Now if I want to view the output file with vi, while process still running: $ vi output.txt Will it kill the process? (seems to me it does). If so how can view the file without... (4 Replies)
Discussion started by: monkfan
4 Replies

10. UNIX for Advanced & Expert Users

Retreive process output

Hi, I had a process that was producing a standard output (no log of it eing produced), unfortunalty the xterm it was running in died and I lost the output. I have logged back in and can see that the process didn't die. How can I bring this process to the foreground so that I can see the output?... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question