Skip to content
Advertisement

Tag: c++

SIZE command in UNIX

The following is my C file: It contains only return statement. But if I use the size command, it shows the output like this: Even though my program does not contain any global variable, or undeclared data. But, the output shows data segment have 252 and the bss have 8 bytes. So, why the output is like this? what is

Child process starts after parent process

I have a simple code to test the fork() function. It didn’t work as I expected. My expectation is: parent’s result and child’s result appear alternately. Can someone explain this and teach me how to fix it? Thanks! Answer The explanation is simple. Scheduling of processes is up to the kernel. If this is a single core processor then in

How fork() function works in this program?

I’m having some trouble with this program. I know what a fork() function does. It is used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. The parent returnes the child’s pid and the child returns 0. That said, I find hard to understand

Why is a multithreaded C program forced to a single CPU on Mac OS X when system() is used in a thread?

I encountered a strange difference in the behavior of a program using pthreads between Linux and Mac OS X. Consider the following program that can be compiled with “gcc -pthread -o threadtest threadtest.c”: Running the resulting executable on a 4-core Mac OS X machine results in the following behavior: Note that the number of actual cores is probably not even

Redirect stdout to a external program in C/C++

I have a program called capture that reads the webcam data and output to the avconv program. Now I have to output to avconv inside my C program. So, instead of output to the stoud: I need to do do something like that: How can I do that? Answer You can use popen() for this purpose. then use fwrite() to

SEGFAULT after recv from socket

I have next trouble: after receiving data from sockets, server app generates segfault and shutdown. Code of client and server side are below. server: Client: In other words, client connected successfully. But after sending message, server generate segm fault error. What went wrong? Answer When running the code it seg faults at: Package is a struct with two members nick

makefile linking does not work (although no error message)

I am having issue with Makefile that I produced. It consists of one .cpp file with main() inside and I want to create executable from it. While putting in terminal make command I get following: While putting first make STutorial.o (.o created) and then make get this: Firstly, why make does not go from the beginning? Secondly, why this reference

Advertisement