c

Multiple child process

hi, can someone help me about how to create multiple child processes which have the same parent in order to do "some" part of particular job? for example, an external sorting algorithm which is applied with child processes; each child process sorts a part of data and finally the parent merges them.. EDIT: Maybe I should mention the f...

Mutual exclusion and C Sockets

I am maintaining an existing system where previous developers on each operation is performed on the socket, to which multiple threads are required to read and write to, the previous developers have performed the io operations under the control and a mutex. is there a requirement to mutually exclude C socket IO operations? Or since socke...

threading concepts

i have started treading in c and also python recently and would like to know any good tutorials available for it ...

Doubt regarding a tail optimized code under 'gdb'

Consider a tail recursive factorial implementation in C: #include <stdio.h> unsigned long long factorial(unsigned long long fact_so_far, unsigned long long count, unsigned long long max_count){ if (max_count==0 || max_count==1 || count >= max_count) return fact_so_far; else { printf("%llu %p \n", count, &factorial); ...

When I run a raw socket program it generates an invalid arguments error.

please help me. i don't find answers for it, after long serch for 2 days iam posting. please help me i very new to socket programing and i written a small code to divert packets at tcp layer for that i used ip_queue's and netlinks with NETLINK_FIREWALL protocol. What i have done is iptables -I OUTPUT -j QUEUE -p udp --destination-port...

How can I strip multiline C comments from a file using Perl?

Can anyone get me with the regular expression to strip multiline comments and single line comments in a file? eg: " WHOLE "/*...*/" HAS TO BE STRIPED OFF....." 1. /* comment */ 2. /* comment1 */ code /* comment2 */ #both /*comment1*/ and /*comment2*/ #has to stripe...

PyImport_Import vs import

I've tried to replace PyRun_SimpleString("import Pootle"); with PyObject *obj = PyString_FromString("Pootle"); PyImport_Import(obj); Py_DECREF(obj); after initialising the module Pootle in some C code. The first seems to make the name Pootle available to subsequent PyRun_SimpleString calls, but the second doesn't. Could someone p...

Multiple child process + reading from a stream

hi, referring to my last question (http://stackoverflow.com/questions/876605/multiple-child-process), i am now trying to make an external sorting implementation using multiple child process. ... fp = fopen(pathname, "r"); // open inputfile in r mode fgets(trash, 10, fp); // ignore first line for (i=0; i<numberOfProcess; ++i) { #ifdef...

Bipartite Matching

How can I implement a bipartite matching algorithm (probably based on a max-flow algorithm) in C or C++ ? To be specific, I have this input in a file: (1,3) (1,5) (2,5) (M,F) --> where M represents id of MALE and F is id of FEMALE. I need to find the maximum number of matches and show matched couples. Like: matches: 1&3 , 2&5 I h...

Assembly compilation error (gcc4.2.4=win, gcc4.3.3=fail).

So, here's a piece of code that recently started causing grief when we upgraded to gcc4.3.3 from gcc4.2.4. void testAndSet( volatile int* s, int* val ) { __asm__ __volatile__ ( "btsl $0, %0\n " "jc bitSet\n " "movl $0, %1\n " "jmp returnVector\n" "bitSet:\n " "...

Is changing a pointer considered an atomic action in C?

If I have a multi-threaded program that reads a cache-type memory by reference. Can I change this pointer by the main thread without risking any of the other threads reading unexpected values. As I see it, if the change is atomic the other threads will either read the older value or the newer value; never random memory (or null pointers...

Pointer to a pointer to a pointer

Duplicate: Uses for multiple levels of pointer dereferences I have a question about C and pointers. I know when I would need a pointer, and even when I might need a pointer to a pointer. An example would be if I had a linked list, and I wanted to write a function that would remove an element of that list, to do so I would need to...

How to tell if stderr is directing output to a file?

Is there a way I can tell whether stderr is outputting to a file or the terminal within a C/C++ program? I need to output different error message depending on whether the program is invoked as: ./program or like: ./program 2>> file ...

Issues with program validation. Please help!!

//Guys I have issues with my code and have been tearing my hair apart trying to resolve this. THe issue is that I am trying to validate my code so it doesn't calculate for negative numbers. If any one can help smooth up this program I would really appreciate it. Please. //The objective of the tax calculator program will be to use C prog...

Linux: socket accept - "Too many open files"

I am working on a school project where I had to write a multi-threaded server, and now I am comparing it to apache by running some tests against it. I am using autobench to help with that, but after I run a few tests, or if I give it too high of a rate (around 600+) to make the connections, I get a "Too many open files" error. After I...

What is the most violent way that an application can terminate itself (linux)

I'd like to emulate violent system shutdown, i.e. to get as close as possible to power outage on an application level. We are talking about c/c++ application on Linux. I need the application to terminate itself. Currently i see several options: call exit() call _exit() call abort() do division by zero or dereference NULL. other option...

Top down and Bottom up programming

Hi all, Why do we say language such as C is top-down while OOP languages like java or C++ as bottom-up?. Does this classification has any importance in software development? Thanks. ...

How can I move C comments from the start of a line to the end using Perl?

Hi all, How can I check for the next line while running in a current loop? Also, how can I move C comments to end of the line for a table? I have a file like this: array_table= { /* comment 1*/ (unsigned int a); /* comment 2*/ (unsigned int b); /* comment 3*/ (unsigned int c); /* comment 4*/ (unsigned int d); } My...

How can I remove the duplication between these C macros?

I have the following couple of C pre-processor macros for creating test functions: // Defines a test function in the active suite #define test(name)\ void test_##name();\ SuiteAppender test_##name##_appender(TestSuite::active(), test_##name);\ void test_##name() which is used like this: test(TestName) { // Test code h...

Is char guaranteed to be exactly 8-bit long in C?

That's all. Didn't find any similar topic so bear with me it there is. ...