C Brain Teaser


 
Thread Tools Search this Thread
Top Forums Programming C Brain Teaser
# 22  
Old 05-11-2007
Quote:
Originally Posted by vino
Cool!

Who is filing it from our forum ?
# 23  
Old 05-11-2007
Quote:
Originally Posted by blowtorch
This is another way of going about it:
Code:
        if((write(fd,buf,strlen(buf)))==-1) {

To me, this violates the requirement to "not make use of files or any extrnal means of storing some data."
# 24  
Old 05-11-2007
Sorry, where is other file used or what is the other means of storing the data here.

The file from which it is run therefore in the binary ( exe ) file the buf is written into and what is the other means of storing the data here ?
# 25  
Old 05-11-2007
Quote:
Originally Posted by matrixmadhan
Sorry, where is other file used or what is the other means of storing the data here.
The executeable is a file and data ""0000000000" is being stored there.
# 26  
Old 05-11-2007
Quote:
Originally Posted by blowtorch
Well, it may be broken, but there is a ETXTBSY error documented in the Solaris open(2) manpage, and this is what it says...
Yeah, but it's not enough to put it on the man page. The kernel needs to operate that way. Your program should not have worked on Solaris.
Quote:
Originally Posted by blowtorch
I don't really understand what a 'pure procedure' means,
In the bad old days, a process was a hodge podge of intermingled code and data. There was no distinction between code and data. A program could rewrite itself on the fly and this was thought to be cool. Then the concept of separating code and data arose. The idea was that "code" (instructions) should not be modified while data needed to be modified. A further refinement occurred when folks realized that some data was constant in nature and also should not be modified. Now the non-modifiable part of a process was renamed to "text". The cpu can guarantee that text is not modified. What's more, if two different users run the same program, both processes can use the same text segment. This is "shared text". Then came virtual memory where a very large program can be run in a small amount of physical memory by paging stuff in-to and out-of core as needed. In virtual memory systems, the text segment is read as it is needed.

This is why the Solaris behavior is so very wrong. If you and I run the same program, our processes share the text segment. If you modify your text segment, you modify mine as well. The separation between processes has been lost. Our entire text segment may not be in core. If you modify the program on disk, we may then page in the modifed data. Our shared text segment can now change, undermining the guarantee that the text segment is stable.

matrixmadhan, I meant that Sun themselves might actually notice that their OS now has unstable processes. If not, then someone with a support contract may raise the issue. A non-customer has no standing to demand repairs on an OS. It's hard enough to get stuff fixed when you are a customer (been there, done that). No way am I going to try to get something fixed as a non-customer.
# 27  
Old 05-11-2007
Quote:
Originally Posted by kahuna
To me, this violates the requirement to "not make use of files or any extrnal means of storing some data."
If we are not allowed to store the output from the compiler into a file, then I will concede defeat. Not only is this challenge impossible, but it is now impossible to run any processes at all.
# 28  
Old 05-11-2007
Quote:
Originally Posted by Perderabo
If we are not allowed to store the output from the compiler into a file, then I will concede defeat. Not only is this challenge impossible, but it is now impossible to run any processes at all.
The original challenge clearly allows the program to be compiled. But it does not allow the program itself to use "files". It does not exclude the executeable file from the no use requirement.
Quote:
Write a C program to do a small task(lets say just simply printing a "Hello World" or so) such that the program should only give output or the desired result ony once after it got compiled and should never give the output nor do anything else. The program should not make use of files or any extrnal means of storing some data.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Cyber Dystopia Teaser (720 HD)

Working on a new cybersecurity, dystopian world series and made a short 2 min teaser today. Cyber Dystopia (720 HD) https://www.youtube.com/watch?v=g9Ca07J_YC8 If anyone has any ideas for the story, please write out some story lines in the comments and join the production team! (1 Reply)
Discussion started by: Neo
1 Replies

2. Shell Programming and Scripting

sed regexp teaser

G'day, Here's a teaser for a sed guru, which I surely am not one, as even my basic sed skills are rusted from years of not practising ... lol Ok ... we have a string of digits such as: 632413741610252847552619172459483022433027602515212950543016701812771409213148672112 we want it split... (9 Replies)
Discussion started by: naderra
9 Replies

3. What is on Your Mind?

The Human Brain project

A global group of scientists are spending the next ten years and a billion dollars to try and develop a computer simulation of the brain: https://www.humanbrainproject.eu/ I always found it fascinating that the brain can understand itself. This almost sounds like in a few years the computer... (0 Replies)
Discussion started by: figaro
0 Replies

4. Programming

Brain Teaser Extended

Hi Gurus, To the Brain Teaser, if I add another condition, say the executable should not be altered, how the program should be altered? (no perl please, purely C). I forgot to mention this condition my staff had mentioned. ( forgot then and got now :D ) The program executed the first time... (4 Replies)
Discussion started by: vrk1219
4 Replies

5. Shell Programming and Scripting

This might be a programming teaser!

Hi gurus, I have done my best to be as precisely as possible with this. Besides giving the format of file a and file b and the result file I have also given the algorithm as I have figured out. I will try to do this and I hope that some of you could help me to solve this or better yet... (1 Reply)
Discussion started by: ljankok
1 Replies

6. Shell Programming and Scripting

Brain Bench Certification

Hi, Can anybody provide me Pointers to Practice tests or any Material to prepare for Brainbench certification in Unix Shell Scripting? Also how good is this Certification for UNIX programmers. Is it worth it? I'm planning to take this certification in 2 weeks. Kindly let me know all the pros... (0 Replies)
Discussion started by: pavan_emani
0 Replies
Login or Register to Ask a Question