Sponsored Content
Top Forums Programming what would happen if a process wrote to its own stdin? Post 302302773 by c_d on Wednesday 1st of April 2009 02:06:37 AM
Old 04-01-2009
Quote:
Originally Posted by pshaikh
Hi

I know that a.out should be executed as "./a.out" , it was typing mistake.

file.txt is redircted as a.out's standard in put. In my program, I am writing to standard input (as shown in the first post)
yes, so the content of file.txt will be written to stdin of a.out

to demonstrate...

Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>


int main(void) 
{
    struct stat st;
    char *whichtty;

    if ( !isatty(STDIN_FILENO) ) 
    {
	    (void) fprintf(stderr, "%s\n", "stdin is not connected to a tty device.");
    } 
    else 
    {
	    if ( (whichtty = ttyname(STDIN_FILENO)) == NULL ) 
	    {
	        perror("ttyname");
            return 1;
	    } 
	    else 
	    {
	        (void) fprintf(stderr, "stdin is connected to tty device %s.\n", whichtty);
	    }
    }

    if ( fstat(STDIN_FILENO, &st) == -1 ) 
    {
	    perror("file status");
	    return 1;
    } 
    else 
    {
	    if ( st.st_mode & S_IWUSR ) 
	    {
	        (void) fprintf(stderr, "%s\n", "stdin appears to be writeable by the user.");
	    } 
	    else 
	    {
	        (void) fprintf(stderr, "%s\n", "stdin does not appear to be writeable by the user.");
	    }
    }
    return 0;
}

OP:
Code:
[c_d@localhost C scratchpad]$ gcc temp.c
[c_d@localhost C scratchpad]$ ./a.out
stdin is connected to tty device /dev/pts/3.
stdin appears to be writeable by the user.
[c_d@localhost C scratchpad]$ ./a.out <temp.c        #this is what you are doing
stdin is not connected to a tty device.
stdin appears to be writeable by the user.
[c_d@localhost C scratchpad]$ chmod -w temp.c  #remove write perm
[c_d@localhost C scratchpad]$ ./a.out <temp.c
stdin is not connected to a tty device.
stdin does not appear to be writeable by the user.
[c_d@localhost C scratchpad]$ chmod +w temp.c

Can someone explain all this to me...or do you think its best I not dig into all this...???

Last edited by c_d; 04-01-2009 at 03:12 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

what happen when changing Hostname?

I 'm using RH 7.2 Genome in the Network Configuration I change therer are two places one for static hostname for my machine and in DNS hostname I don't know what happen when restarting my PC when connecting using dialer I can't browse the Internet also I can't use sendmail .......Server timeout... (2 Replies)
Discussion started by: atiato
2 Replies

2. Programming

Any one can tell me how this happen?

The #1 Online Store for Louis Vuitton Replicas is: http://www.opichina.com.cn. We offer Louis Vuitton Replicas and more! Whatever you call it: LV Bags, LV Replicas, Louis Vuitton Fake, Louis Vuitton Knockoffs, Louis Vuitton Bag, Louis Vuitton Purse, Louis Vuitton Wallet, Louis Vuitton Shoes,... (10 Replies)
Discussion started by: jiangyanna
10 Replies

3. UNIX for Dummies Questions & Answers

What would happen if. . .

Hi, Could someone please tell me what would happen if the following were entered into the command line: rm -i /books/*.* rm /books/* Many thanks! (3 Replies)
Discussion started by: crispy
3 Replies

4. UNIX for Advanced & Expert Users

Unix ID deleted - What happen to process

I have an unix id (AIX system) which is used to run a couple of processes. They also write some log files into a file system (that is not in the home directory of the user id, but in different location). One bad day, the id was deleted accidentally. But the home directory, files and everything... (1 Reply)
Discussion started by: cmgreat
1 Replies

5. UNIX for Dummies Questions & Answers

whats happen when we create new user

hi frndz I wanna knw exatly what happen when we create new user... which directories are created ?? which files are modified ?? thanx.... (2 Replies)
Discussion started by: luckypower
2 Replies

6. AIX

How does ITIL processing happen in AIX?

How does ITIL process is implemened in AIX? (6 Replies)
Discussion started by: AIXlearner
6 Replies

7. UNIX for Dummies Questions & Answers

What Does Happen During Boot Process? - BIOS and MBR

I'm talking about boot process in multi-boot Linux perceptive. Please tell me whether my explanation is right or wrong? If wrong, please explain. "The BIOS checks the system and loads this initial bootstrapping code into memory. This initial bootstrap code searches for an active partition... (0 Replies)
Discussion started by: f.ben.isaac
0 Replies

8. UNIX for Advanced & Expert Users

Who actually wrote Professional Linux Programming ?

Hello, Who actually wrote Professional Linux Programming of Wrox publication as there are two different sets of writers, one set consists of Jon Masters and Richard Blum and another set of writers is Neil Mathew with lots of other writers. Plz resolve it. I'm really confused. Regards.. (0 Replies)
Discussion started by: vectrum
0 Replies

9. Shell Programming and Scripting

Crontab - wrote Simple Script but i cant work out how to play it at a certain time.

Hi everyone. Silly might be silly be I'm still new to bash. I'm trying to make an Alarm Clock for in the morning using my laptop i have wrote this Simple Script but i cant work out how to play it at a certain time. #!/bin/bash cd /home/josh/Music/Bruno_Mars/Hooligans/ cvlc... (8 Replies)
Discussion started by: jtsmith90
8 Replies

10. What is on Your Mind?

Ah, the AMIGA, (another poem I wrote in 2005).

Well I wrote this in 2005 and uploaded to AMINET.as a commemoration of a machine that is still in use today. It is now 29 years since this machne came into being. Phenominal and it is still being supported- WOW! My A1200 is on 24/7 and I use it to test code developed on AMIGA emulators... ... (0 Replies)
Discussion started by: wisecracker
0 Replies
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 08:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy