Sponsored Content
Top Forums Programming Multithreading in reading file Post 302576126 by Corona688 on Wednesday 23rd of November 2011 05:08:45 PM
Old 11-23-2011
Code:
$ cat getsecsal.c

#include <stdio.h>
#include <string.h>

int main(void)
{
        char buf[16384];
        char section[16384];

        while(fgets(buf, 16384, stdin))
        {
                char *substr;
                if(substr=strstr(buf,"<Section>"))
                {
                        substr += strlen("<Section>");
                        char *end=strstr(substr, "</ Section>");
                        if(end) (*end)='\0';
                        strcpy(section, substr);
                }
                else if(substr=strstr(buf,"<Salary>"))
                {
                        substr += strlen("<Salary>");
                        char *end=strstr(substr, "</Salary>");
                        if(end) (*end)='\0';

                        printf("%s~%s\n", section, substr);
                }
        }
}

$ gcc getsecsal.c
$ ls -lh data[12]
-rw-r--r-- 1 tyler users 1.7G Nov 23 15:57 data1
-rw-r--r-- 1 tyler users  208 Nov 23 15:57 data2
$ cat data2

<EMPLOYEE>
<RECORD id =XYZ >
<SSN>123</SSN>
<Section>dfdf</ Section>
<Salary>34343</Salary>
</RECORD>
<RECORD id =XZY >
< SSN >321</ SSN >
<Section>dfd</ Section>
<Salary>34343</Salary>
</RECORD>
</EMPLOYEE>

$ ./a.out < data2
dfdf~34343
dfd~34343

$ time ./a.out < data1 > /dev/null

real    0m46.661s
user    0m42.820s
sys     0m2.221s

$

1.7 gigabytes of data in 46.7 seconds is 37 megabytes per second -- the fastest speed my disk controller gets. I'd need a faster disk controller to do any better. More threads wouldn't do a thing.

If the tags in any of your records are actually different from what you posted, it won't work.
This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. Programming

Multithreading in Pro*C

:confused: Hi! I have created a Multhreaded Application in Pro*C (using pthreads) with about 5 Threads running simultaneously. The Application is basically to Update a Centralized Table in Oracle, which updates different rows in the Table (Each Thread updates different rows!). The... (16 Replies)
Discussion started by: shaik786
16 Replies

2. Programming

multithreading on OSX

Hi all, I have a query about multithreading. What I would like to do is, at the start of my main update() function, start a couple of threads in parallel, once they are all complete carry on with my main update function. void update() { thread1->update(); // fluid solver ... (3 Replies)
Discussion started by: memoid
3 Replies

3. UNIX for Advanced & Expert Users

multithreading in UNIX

Hi, Can you please give me a suitable reference to learn multithreading programming in C in UNIX? Thanks (3 Replies)
Discussion started by: naan
3 Replies

4. Shell Programming and Scripting

Multithreading program

Hi I need to insert 1million records into MySQL database, but it is taking lot of time as there is no bulk insert support. I want to spawn 10 processes which will insert 100k records each parallely. Can somebody help me with a example program to execute this task through shell scripting. (5 Replies)
Discussion started by: sach_roger
5 Replies

5. Programming

MultiThreading using Pthreads

Situation: i have multiple pthread_create calls like this: pthread_create(...., ThreadFunc1,.....); pthread_create(...., ThreadFunc2,.....); . . which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same... (3 Replies)
Discussion started by: Sastra
3 Replies

6. IP Networking

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Discussion started by: moti12
0 Replies

7. Programming

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
Discussion started by: moti12
6 Replies

8. What is on Your Mind?

Alarm interrupt and multithreading

Hi Friends any know how became a friend in this Android Programming Language (0 Replies)
Discussion started by: ljarun
0 Replies

9. Programming

Help with multithreading

I take this question of the The Linux Programming Interface: A Linux and Unix System Programming page 652 exercise 30.1 I want someone to explain the under line statement because it sounds complex to me couldn't understand anything 30-1 Modify the program (thread_incr.c) so that each loop in... (3 Replies)
Discussion started by: fwrlfo
3 Replies
Graph::Reader::XML(3pm) 				User Contributed Perl Documentation				   Graph::Reader::XML(3pm)

NAME
Graph::Reader::XML - class for reading a Graph instance from XML SYNOPSIS
use Graph::Reader::XML; use Graph; $reader = Graph::Reader::XML->new(); $graph = $reader->read_graph('mygraph.xml'); DESCRIPTION
Graph::Reader::XML is a perl class used to read a directed graph stored as XML, and return an instance of the Graph class. The XML format is designed to support the Graph classes: it can be used to represent a single graph with a collection of nodes, and edges between those nodes. The graph, nodes, and edges can all have attributes specified, Graph::Reader::XML is a subclass of Graph::Reader, which defines the generic interface for Graph reader classes. METHODS
new() Constructor - generate a new reader instance. $reader = Graph::Reader::XML->new(); This doesn't take any arguments. read_graph() Read a graph from a file: $graph = $reader->read_graph( $file ); The $file argument can be either a filename or a filehandle of a previously opened file. KNOWN BUGS
Attribute values must be scalar. If they're not, well, you're on your own. SEE ALSO
Graph::Reader The base class for Graph::Reader::XML. Graph::Writer::XML Used to serialise a Graph instance as XML. Graph Jarkko Hietaniemi's classes for representing directed graphs. AUTHOR
Neil Bowers <neil@bowers.com> COPYRIGHT
Copyright (c) 2001-2012, Neil Bowers. All rights reserved. Copyright (c) 2001, Canon Research Centre Europe. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-02-14 Graph::Reader::XML(3pm)
All times are GMT -4. The time now is 02:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy