Programming :: Get Similar Results Using Both Gcc And G++
Mar 7, 2011
consider these lines of code and their outputs:
[CODE]
int C = 0;
fprintf(stdout, "
(C, ++C) Bef = %d, Aft = %d
", C, ++C);
fprintf(stdout, "(C++, C) Bef = %d, Aft = %d
", C++, C);
[Code].....
The only one that looks right to me is the second one. I get similar results using both gcc and g++.
View 4 Replies
ADVERTISEMENT
Dec 27, 2010
I am building a queue system (in C on CentOS 5) where each directory queue has a number of process instances 'watching' it. I have a root-permission queue supervisor process which does all the forking, and the instance processes give up root as their first action. For max security each queue is accessible to a different set of users and groups.
I need to keep the RAM requirements as low as possible, so I am relying heavily on copy-on-write (since all memory writes are to shmget() shared memory)
Each process presently dlopen's the libraries it requires after fork, but I'm wondering if I would gain by performing the dlopen before forking a number of instances which all require the same libraries.
Any pointers to mid-level tutorials on dlopen and fork internals would be most appreciated: this is about my third post anywhere since I converted to Linux, but I just can't find the answer to this anywhere online.
View 3 Replies
View Related
Feb 8, 2011
Is it possible to create a loadable module for a C app that could be loaded into the app in runtime from a CLI or web interface?I would like the code to handle a particular type of structure to be "swappable" for lack of a better term. This would allow different modules to be used based on the users wants without having to mess with code. A different module could be downloaded into the application directory then loaded. Basicaly the code would be handed a pointer process it then return it.
View 2 Replies
View Related
May 10, 2010
Im having problems with this little thing in a C example Im doing. I want to show in the shell like this example:
Name Birthday
Tomas 13
Adrian 24
Nate 15
Im trying to use the printf function but the names doesnt have the same lenght. So I cant do it like this:
printf("Name Bithday
");
printf("%s %d
");
View 4 Replies
View Related
Apr 13, 2010
i have a loop which produces new value everytime it runs. i want to store the results in an array. how can i do dat??
loop is like:
a=0
declare v
while ((....))
do
v[$a]="$r"
let a=a+1
done
while doing this it is not treating v as array but as variable and it is overriding the value and old value is lost..i am using bash shell version 3.00.15
View 5 Replies
View Related
May 5, 2010
I have this multiline variable code...
View 5 Replies
View Related
Jul 25, 2011
I have a socket library that I tinker with from time to time. Lately, I decided to expand it to support IPv6.
One of the issues I am having is sending data, using sendto(). When the server receives data from a client, using recvfrom(), it does not retain the sockaddr_in information, but instead provides the callee the IPv6 address and port number from where the data originated. See here:
Code:
int
UDPSocket::recv(char* buffer, size_t bufferLen, std::string& sourceAddr, unsigned short& sourcePort)
{
sockaddr_in sin;
socklen_t sinLen = sizeof(sin);
[Code]....
View 8 Replies
View Related
Apr 1, 2010
I've a web page where I can search information in my database.Sometimes results of search operation are more of fifty.How can I split results in different web page as it happens for example in any search engine or operation
View 7 Replies
View Related
May 21, 2011
I was looking for a method of allocating memories on Linux which similar VirtualAlloc on Windows.Requirements are:
1. Size of memories block to allocate is 2^16.
2. Address of memories block is larger than 0x0000ffff
3. Address of memories block must have last 16 bits are zero.
On Windows because lower limit of application address (lpMinimumApplicationAddress) we have (2) obvious right. From (1), (2) and system rules we also achieved (3).
View 2 Replies
View Related
May 30, 2010
I have a simple class that encrypts strings. It seemed to be working fine until I tried to compare the decrypted values to the original. below is the output of the php code. It appears to be decrypted but the length is incorrect.
String Before Encryption: a text string
String Length Before Encryption: 13
String After Encryption: rew2iSYotruIpmJ3llos3A==
[code]...
View 7 Replies
View Related
Feb 8, 2011
I'll post the entire code here, and then specifically highlight what is just failing in a fashion I'm apparently incapable of fixing a few hours later:
Code:
#!/usr/bin/expect
# The script should be called with a file in the directory called sshServerList
# That file has the following format:
# Line # | Contents of line
[code]....
I've had all kinds of different results and problems, but I've never been able to successfully log into multiple servers, though the first server in the list most times works okay (though might not on this iteration). I'm a bit hack and slash and I would be very greatful not only for a solution, but any tips on how I should have done this and places where I could clean up my code.
View 1 Replies
View Related
Jan 20, 2009
How do I find for example the 4th to the 9th result in a particular SELECT query?
View 6 Replies
View Related
May 25, 2010
I'm sure this has been covered somewhere before, but I couldn't find anything and so figured I would post here. I have been using Linux OSes for the past couple of years and also using GCC/G++ for application development. However, I have almost always been on x86 systems and never gained much experience using the wide range of optimization options available.
My question is, if I do not specify the -march=PROCTYPE option, will GCC still be able to detect the current architecture and build the code accordingly? I primarily ask this because I am working with an x86_64 system, and specifying -march=x86_64 in my makefiles generates errors about it being an unknown processor type, even though the CPU and OS are X86_64. I know this sounds like a newbie question, but it's just ground I've never had to cover before until now.
View 7 Replies
View Related
Dec 11, 2010
trying to see IF i dont get the right results repeat the command until it will or quit after 3 tries....
expect -exact "->"
send -- "test_read_register 0,0x37
"
if {! [regexp {Address 0x00000000} do send -- "test_read_register 0,0x37
[code]....
It should read
Read: Address 0x00000037, Data: 0x0000000b
but sometimes it comes out to this
Read: Address 0x00000000, Data: 0x00000000
therefore ill have to run the command again IF I Dont get the right results...
View 1 Replies
View Related
May 9, 2011
I am having trouble with encryption/ decryption program. The program goes out and finds the file I want it to, encrypts it into a continuing series of a single repeated negative number, then generally decrypts(or should i say re-encrypts)it into a widely repeated character, different but same results every time.
[Code]....
View 3 Replies
View Related
Jul 8, 2011
I ran the command:
Code:
ls -ltr | head -n40
I'd like to delete all the files listed...
View 2 Replies
View Related
Sep 15, 2010
I am querying a single string column in a table. The string values have spaces in them. I want to loop over each value in bash. I set IFS to split lists on newlines instead of spaces. When I try this, it is splitting the list of results on the actual character 'n', not the newline ''.
DATA=`mysql -u root -ppassword --silent 'SELECT name FROM table_a;'`
IFS=$'
'
for i in $DATA; do
echo "item = $i"
[Code]....
View 5 Replies
View Related
Feb 7, 2010
how do I achieve the result but here is the story. I have a script which prompts for the IP Address and read that value and validate if reachable. If not then it should keep on prompting until the IP is reachable. I tried using until loop as well as while loop but dang..Here are the codes
#!/bin/bash
IP_Feed () {
echo -n "Give me IP : "
[code]....
View 4 Replies
View Related
Dec 7, 2010
I used wait4 to time a child process. but the results differ each other dramatically. why?my core source code lists as below.to the point: in linux 2.6 kernel, how to time a process with a high precision. and, only its user-time rather than the elapsed time???
static struct rusage ruse;
static pid_t u_pid;
int main(int argc, char *argv[])
{
int i;
code....
View 14 Replies
View Related
Nov 2, 2010
I am trying to store the results of my code to a separate text file.But the problem is, as my results comes from a loop, my text file shows only the last result, not all of them.Like if the loop runs 5 time the text file shows the result for the 5th step.But i need to store all of them (1 to 5).Can I use awk to print the output field and store to another file and creat a new line so that the next output field goes to a new line?(just an idea, dont know).
#!/bin/basth
for (( i=1; i<=5; i++))
do
./file.exe > output.txt
done
View 2 Replies
View Related
Jun 5, 2009
I want to remove duplicate or multiple similar lines from multiple files. I.e. if I have four files file1.txt file2.txt file3.txt and file4.txt and would like to find and remove similar lines from all these files keeping only one line from these similar lines. I only that uniq can be used to remove similar lines from a sorted file.
View 9 Replies
View Related
May 5, 2011
(bare with me as I am sort of new with scripting) I am trying to figure out how to run a script that does a basic chkconfig and to get only those services that are running, but changing the color of "on" to red in my output file. Here is what I am working with so far:
Quote:
#/bin/bash
RED=$(tput setaf 1)
BLK=$(tput setaf 0)
[code]....
*I had to substitute a "-" and <colon_symbol> for ":" in front of the on's, because the forum thought they were smiley faces (i.e. n) how to make the "on" to be red while the rest of everything remains in black text. I have been trying to read up on sed and awk, but it is still pretty much a mystery to me right now. There will be other things in the output file that I wouldn't want a rogue "on" to be in red, so just the instances of "on" in that one chkconfig return.
View 4 Replies
View Related
Mar 12, 2010
Basically the requirement of the script are :
1. need to run like a daemon which will read an active squid logfile in a refresh pattern of 5 minutes
2. calculate the total number requests based on different domains that the client access
3. calculate the total of number of requests based on different domains as well as the turnaround time of these access is more than 5 sec that the client access
4. calculate percentage of item 3 over item 2
5. report the results in html format as follows:
Domain Name Total req Req > 5 sec % of req > 5 sec
6. able to access the results from web browser.
View 8 Replies
View Related
Apr 6, 2010
I'm timing how long it takes to run a command foo. I'm looking to append the results from the time command to a file, and discard the results from the foo command. I tried the following, but it didn't do what I want:
$ time ./foo > /dev/null >> output_from_time_command.txt
View 1 Replies
View Related
Aug 26, 2010
Is there a perl module that will let me turn numbers into human readable measures of time? For example, 1280513294 would be "26 days ago". If so, what's its name?
View 2 Replies
View Related
Jun 5, 2011
I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax.
Code:
if [ $# -eq 0 ] ; then
d=`pwd`
for i in * ; do
if test -d $d/$i ; then
echo "$i:"
code....
View 10 Replies
View Related
Dec 1, 2010
Im reading in file /proc/cpuinfo into a char array.Im using strstr to search for a string im interested in (the cpu speed line) and storing it in another char array.I want to just store the line that contains CPU speed but im getting everything after the CPU speed line in the char array too.Is there anything better than strstr or is there someway i can parse the the payload data (i.e. the actual cpu speed)
View 4 Replies
View Related
Jun 8, 2010
how to set the subject of this up.. but here is what I am trying to accomplish (please keep in mine, this is only my first month playing with ANY Linux programming): My shared web host limits running 2 CRONS or 2 SSH sessions at one time. I need to run more than that.. So, my solution is to run what I need on my home computer, and then push all the results via SSH to my web server.
To keep things timed, I am trying to call 4 bash scripts from inside of 1 bash script... Each bash script has variables I need to export out to the remote (web) server. Being that I can only run 2 SSH or 2 CRON sessions on the remote, it wouldn't do me any good to open up CRON or SSH remotely or locally - either way I'm maxing out. That is why I would like to call 1 final script that takes the output of the 4 bash scripts and does the job.
Main bash calls via CRON every 30 minutes:
Code: ./script_1 &
./script_2 &
./script_3 &
./script_4 &
[code]....
I need to scp the file saved by wget to the remote server. I also need to pass the SQL statement generated in each script as a command in SSH. I'm lost how to get the info from "script_x" into a string that can be used to SSH - and doing this all inside of ONE SSH command. Would I store the SQL strings in a file and call that in the SSH command line?
If so, what is the command to make sure the variable output in the "script_#" file is sent to a file? Can I call the variable from the main Bash Script? Now - the good news is, I can SSH from my local machine to the remote one.That is about as far as I got.Again - I am so new to this that my ears are still wet. This has been something I have been working on for a while, and I'm just lost at this point.
View 2 Replies
View Related
Apr 5, 2011
I have a log file with entries such as;
Where result is 0 or more.
I want to get the list of file names where result count is more than 0 (in other words filter out files names with result 0).
File name and result are in two different lines in log file.
How can i filter file name based on result?
View 5 Replies
View Related
Aug 14, 2010
Dear experts,I have a question about open() function of gcc3.4.6.I write a example:
Code:
using namespace std;
#include<iostream>
#include<fstream>
int main()
{
[Code].....
It can be compiled and ran.The statement file=txt_stream_file is in order to change char* to const char*. But open() function is not work,and out: can not open plots/results.txt The open() function of gcc3.4.6 is:
[Code]....
View 4 Replies
View Related