Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:07:29+00:00 2026-06-06T15:07:29+00:00

I wrote a simple C program: #include <unistd.h> #include <stdio.h> int main( int argc,

  • 0

I wrote a simple C program:

#include <unistd.h>
#include <stdio.h>

int main( int argc, char *argv[] ) {
  printf( "%s\n", getlogin() );
  return 0;
}

… to try some things out. I’ve tried making getlogin() fail by making sure there isn’t a controlling terminal, but it’s still getting the login name and printing it. The most extreme example to demonstrate this:

#!/bin/bash
for i in $(env | grep -vP ^PATH\\b | awk -F= \{print \$1\}); do
  unset $i;
done;
(tty; perl -e 'setpgrp; sleep( 1 ); exec( qw( getlogin_test ) );' ) &

In the way of explanation: it un-sets all environment variables except PATH, then runs a sub-shell that executes ‘tty’ then a perl instance; the sub-shell is backgrounded. Calls setpgrp to make sure it isn’t using the process group to find the parent’s controlling terminal (I don’t believe it does, but I put it in there in case that assumption was wrong).

At this point, I’m at a loss. It still prints the username. A simpler example that I’ve seen from quite a few sources has the same behavior:

sh -c 'time perl -e '"'"'$|=1; print getlogin(), chr(10);'"'"' &'
sh -c 'time perl -e '"'"'$|=1; print getlogin(), chr(10);'"'"' & wait'

Both of these still print the username, under both Solaris 10 and Redhat 6 with differing versions of perl, bash, sh, and tcsh.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:07:30+00:00Added an answer on June 6, 2026 at 3:07 pm

    Closing or redirecting STDIN to a file does the trick.

    $ perl -wE'say getlogin()'
    eric
    
    $ perl -wE'open STDIN, "<", "/dev/null" or die $!; say getlogin()'
    Use of uninitialized value in say at -e line 1.
    

    This is a self-built Perl (default options) on a Debian box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <unistd.h> #include <stdio.h> #include <string.h> #include <sys/sendfile.h> #include <sys/stat.h> #include <fcntl.h> int main(){
I'm new to linux programming. I wrote a very simple program: #include stdio.h #include
I just write a simple program to print the address of variable. #include <stdio.h>
Code: #include<stdio.h> #include<malloc.h> struct details{ char *name; int no; struct details *info; }; //ADDING
I wrote a simple program to test array pointer: #include <iostream> using namespace std;
I wrote a simple c++ program that prints Hello World! #include <iostream> using namespace
I wrote a simple program for handling some of the signals. My Program is,
I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B
I wrote a simple program to test a theory that finally block will always
I wrote a simple program in java web forms but i am receiving the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.