On a linux shell deleting files is quite straightforward as it is expected just do rm fileName..
And if you have group of files which has a particular pattern and if you want to delete them, you do rm * < pattern >. But what do you do if you want to retain files with a particular patter and remove all other files in that directory.. This happens to me when I run some code for my work. My folder gets completely loaded with lot of log and tmp files which are produced by the main program. So how do I remove them ?
On a zshell its quite easy.. Say if you want to retain the files starting with the name mypetfile.
just do rm ^mypetfile*..
all the files which are not starting with the mypetfile is gone !!!
Monday, April 18, 2011
Parallel processing on bash shell
Straight to the idea:
suppose you are working on a machine which has some 16 cores. And you have a heavy program which generates particle events and outputs to a file. You can make the whole thing parallel process on the shell.
Here we go.
The program name toyMC
the program is run with an argumen n_events. The program reads this number and generates "n_evetns" number of MonteCarlo evetns and writes it into and output file evGen.txt
How do we parallelize this
Say we run 100 parallel instances of this program:
first creat 100 directories and then "cd" to these directories and run the code.
It is safe to do it this way.. otherwise multiple instances of the program might access the file and it will be a great mess.
The Full command on bash:
for i in `seq 1 1 100; do (mkdir job${i}; cd job{$i}; ../toMC 100 & ); done
thats it...
warning: the macro is not tested.
suppose you are working on a machine which has some 16 cores. And you have a heavy program which generates particle events and outputs to a file. You can make the whole thing parallel process on the shell.
Here we go.
The program name toyMC
the program is run with an argumen n_events. The program reads this number and generates "n_evetns" number of MonteCarlo evetns and writes it into and output file evGen.txt
How do we parallelize this
Say we run 100 parallel instances of this program:
first creat 100 directories and then "cd" to these directories and run the code.
It is safe to do it this way.. otherwise multiple instances of the program might access the file and it will be a great mess.
The Full command on bash:
for i in `seq 1 1 100; do (mkdir job${i}; cd job{$i}; ../toMC 100 & ); done
thats it...
warning: the macro is not tested.
Thursday, February 17, 2011
Checking memory usage of a particular process in Linux/Unix
When you write codes which are to be performance enhanced, taxing only a few on the the host machines physical memory, you need to think a lot and come up with a smart design. I am not an expert in software design. If at all I know something about this field its all through the book which Sebastian gave me[Don't remember the name of the book ].
Alright... Today I found out how to log the memory usage of a particular process on Linux. Here is how it works
The linux command pidof aprocess will return the process id or job id of the process.
Then all you have to do is to check the status of this process in /proc/jobid/status.
cat /proc/`pidof aprocess`/status.
Just try it out. Will explain later what are the parameters listed in this file..
Alright... Today I found out how to log the memory usage of a particular process on Linux. Here is how it works
The linux command pidof aprocess will return the process id or job id of the process.
Then all you have to do is to check the status of this process in /proc/jobid/status.
cat /proc/`pidof aprocess`/status.
Just try it out. Will explain later what are the parameters listed in this file..
Subscribe to:
Posts (Atom)