split command


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users split command
# 8  
Old 01-12-2010
IMO, you are missing the point. sync(), fdatasync(), fsync() force the kernel to write to disk/device all pending write operations - fsync() works on a single stream...fflush() calls fsync(). If a process abends without flushing stdout the output is lost period.

If your process IS ACTUALLY writing everything before it dies, then the problem lies with split. Which I doubt. Can you post the last few lines of output from your app (do not use split) when it hits error conditions?

For example: If you call _exit() rather than exit() in your code it will NOT flush output.

example 1:
Code:
#include <signal.h>                
#include <stdio.h>                 
                                   
int main()                         
{                                  
   int i=0;                        
   for(i=0; i< 2048; i++)          
   {                               
       if(i==1024) raise(SIGSEGV); 
       printf("x");                
   }                               
   return 0;                       
}

output:
Code:
> cc t.c
> ./a.out
Segmentation Fault(coredump)

Note -- NO output. Why? because the process did not flush stdout.

example2: using split, my version of split does not support -d:
Code:
> ./a.out | split -b 10m  -a 1 - "myappLog"                               
> ls -lrt | tail                                                          
-rw-r--r--   1 a     b        1799 Jan 11 11:53 WithSB_After_ChargeCalc.sql
-rw-rw-r--   1 a     b         329 Jan 11 11:53 after_estimates.txt        
-rw-r--r--   1 a     b         354 Jan 11 12:15 sql_threads.h              
drwxrwxr-x   2 a     b        2048 Jan 11 13:19 data                       
-rw-r--r--   1 a     b       22375 Jan 12 09:23 threadbud.pc               
-rw-r--r--   1 a     b        1384 Jan 12 09:28 ClearPrdgForLateMRE.sql    
-rw-------   1 a     b        7276 Jan 12 10:02 dead.letter                
-rw-r--r--   1 a     b         172 Jan 12 11:14 t.c                        
-rwxrwxr-x   1 a     b        6648 Jan 12 11:14 a.out                      
-rw-------   1 a     b      113228 Jan 12 11:19 core

No file produced.

example calling exit():

Code:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void signal_handler(int sig)
{
	  exit(1);
	  
}

int main()
{
   int i=0;
    signal(SIGSEGV,signal_handler);
   for(i=0; i< 2048; i++) 
   {
       if(i==1024) raise(SIGSEGV);
       printf("x");
   }
   return 0;
}

output from exit():
Code:
app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xxxxxxxxx
>

1023 bytes on stdout.

running thru split:
Code:
> ./a.out | split -b 10m  -a 1 - "myappLog"
> ls -lrt | tail
-rw-rw-r--   1 appworx  banner       329 Jan 11 11:53 after_estimates.txt
-rw-r--r--   1 appworx  banner       354 Jan 11 12:15 sql_threads.h
drwxrwxr-x   2 appworx  banner      2048 Jan 11 13:19 data
-rw-r--r--   1 appworx  banner     22375 Jan 12 09:23 threadbud.pc
-rw-r--r--   1 appworx  banner      1384 Jan 12 09:28 ClearPrdgForLateMRE.sql
-rw-------   1 appworx  banner      7276 Jan 12 10:02 dead.letter
-rw-------   1 appworx  banner    105004 Jan 12 11:26 core
-rw-r--r--   1 appworx  banner       277 Jan 12 11:27 t.c
-rwxrwxr-x   1 appworx  banner      6852 Jan 12 11:27 a.out
-rw-rw-r--   1 appworx  banner      1024 Jan 12 11:31 myappLoga

myapp is the problem not split. IMO.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with Split Command

Hi All, I have a txt file which I would like to partition into 2 separate output files. I would like to partition the odd or even groups of 4 lines from the txt file. So I would like lines 1-4 to go to file1, and lines 5-8 to go to file2, and so on until the whole txt file is divided into two... (1 Reply)
Discussion started by: landrjos
1 Replies

2. UNIX for Beginners Questions & Answers

Urgent..!!Split command

Hi All, I want to split the file after size gets above 100kb. So I am using below command. split -b 100kb File.txt Test But after first file, my record is breaking as in middle of the record, size of file is getting above 100kb. So after splitting half record is in one file and half... (1 Reply)
Discussion started by: Amey Dixit
1 Replies

3. Shell Programming and Scripting

Want to split awk command

Hi, There is an awk command in script and it is running successfully. I want to split that command in 2 lines. I have tried using '\' but its not working.. Please suggest me the solution. (11 Replies)
Discussion started by: Sanket Dalvi
11 Replies

4. UNIX for Dummies Questions & Answers

Split command

Hi I have a sequence which looks like this # PH01000000 PH01000000G0240 P.he_genemodel_v1.0 CDS 120721 121773 . - . ID=PH01000000G0240.CDS;Parent=PH01000000G0240 PH01000001G0190 P.he_genemodel_v1.0 mRA 136867 137309 . - . ID=PH01000001G0190.mRNA;Parent=PH01000001G0190... (7 Replies)
Discussion started by: siya@
7 Replies

5. UNIX for Dummies Questions & Answers

change split with another command

hi all, i have problem with my script in unix ...i have script with split -d (--numeric-suffixes) in linux its working but in solaris machine the option -d isn't have so how to i can change split -d (this output) will same in output solaris can i change with awk and how do that thx before (2 Replies)
Discussion started by: zvtral
2 Replies

6. UNIX for Dummies Questions & Answers

filenames from split command

Is there an option or a way with the split command to rename the partitioned files with a counter. For example, can the files testaa, testab, testac be renamed to test1, test2, test3 from the split command without explicilty renaming files. Thanks, - CB (3 Replies)
Discussion started by: ChicagoBlues
3 Replies

7. UNIX for Advanced & Expert Users

Split Command in Perl

Hi, I have to split a line of the form 1232423#asdf#124324#54534#dcfg#wert#rrftt#4567 into an array in perl. I am using @fields; @fields=split('#',$line); if($fields eq "1") But this is not working. By using the syntax, the statements in "if" are never executed. Please help.... (9 Replies)
Discussion started by: rochitsharma
9 Replies

8. UNIX for Advanced & Expert Users

Split Command options

HI! All iam using Split command to split a large .txt file in to smaller files, The syntax iam using split -25000 Product.txt iam getting four output files but not in .txt format but in some other format , when i checked the properties the Type of the output files is Type can any... (7 Replies)
Discussion started by: mohdtausifsh
7 Replies

9. Shell Programming and Scripting

Split command

Can anyone tell me what this command will do? split -b$SPLITSIZE - $file1 < $file2 Will it split file1 or file2? Please explain. Malay (1 Reply)
Discussion started by: malaymaru
1 Replies

10. UNIX for Dummies Questions & Answers

Problem in split command

I want to split a file containing millions of records. I am issuing the command split -l 20000 filename which will split the file in 20K records each. It works fine except in some files, data after one particular field is lost( the field with space). Say the record is ... (4 Replies)
Discussion started by: superprogrammer
4 Replies
Login or Register to Ask a Question