Sponsored Content
Top Forums Programming fork/exec clobbers write. I need ideas why... Post 302119209 by frequency8 on Monday 28th of May 2007 10:37:19 PM
Old 05-28-2007
When I run
Code:
#include <unistd.h>
#include <stdlib.h>

int main(int argc,char **argv)
{
  execlp("tel","tel",argv[1],argv[2],NULL);
  return 1;
}

I get the following
[cda@localhost ~]$ ./flood2 cda "la\\nla\\nla\\n"
cda logged on more than once
Telegram to pts/2...Telegram from cda on pts/2 at 19:22 PDT ...
la\nla\nla\n
SENT
EOF (cda)

[cda@localhost ~]$ ./flood2 cda la\\nla\\nla\\n
cda logged on more than once
Telegram to pts/2...Telegram from cda on pts/2 at 19:24 PDT ...
la\nla\nla\n
SENT
EOF (cda)

The exact same behavior as if I were just passing the strings via tel. Notice how the '\n' doest get 'interpreted'

Now I'm really puzzled as to why, when I fork the process, the newlines get interpreted. Could is be maybe some kind of funy shell trick tel might be doing?

I know in wrt_sig.c, there is the following sheep trick with the shell
Code:
#ifdef USER_SHELL
/* WSYSTEM:  A modified version of the system() command that uses the user's
 * own shell (as specified by the "SHELL" environment variable) instead of
 * always using sh.
 */

void wsystem(char *cmd)
{
register int cpid,wpid;
RETSIGTYPE (*old_intr)(), (*old_quit)();
char *shell;

        if ((cpid = fork()) == 0)
        {
            dup2(2,1);
            /*setuid(getuid()); setgid(getgid());*/
            endutent();
            if ((shell= getenv("SHELL")) == NULL) shell= "/bin/sh";
            execl(shell,leafname(shell),"-c",cmd,(char *)NULL);
            fprintf(stderr,"%s: cannot execute shell %s\n", progname,shell);
            exit(-1);
        }
        old_intr = signal(SIGINT,SIG_IGN);
        old_quit = signal(SIGQUIT,SIG_IGN);
        while ((wpid = wait((int *)0)) != cpid && wpid != -1)
            ;
        signal(SIGINT,old_intr);
        signal(SIGQUIT,old_quit);
}

 

10 More Discussions You Might Find Interesting

1. Programming

Fork and exec

Hello! I am working on a server where I should have 4 (resident)processes, one of them being "the father" of the others, so I do 3 forks. The problem that I have is that I do an accept (for sockets) in the "father" process and I want to transmit the job to one of the processes "child" with... (3 Replies)
Discussion started by: driki
3 Replies

2. UNIX for Dummies Questions & Answers

FORK/EXEC technique

Hi! Can someone explain me exactly this technique? Why a process (PARENT) creates a copy of itself with FORK (CHILD)? What's the reason of this behaviour? Sorry, but I cannot understand the logic behind it. Thanks. (4 Replies)
Discussion started by: marshmallow
4 Replies

3. Solaris

fork and exec ftp

Hi, I need to find/implement an application that FTPs (puts) all new files in a certain directory to an external storage unit. This application should check for new files every 10 seconds (leaving the FTP connection open in between the 10 seconds). The easiest way would be if there are... (2 Replies)
Discussion started by: KittyJ
2 Replies

4. UNIX for Dummies Questions & Answers

How to write a script by fork() in unix

Hello to UNIX Champs, Can any body help me out to write the script using fork() thru shell scripting.....i am a layman to fork(), so please give me the link or any scripts which will help me out to know the details about fork. (1 Reply)
Discussion started by: manas_ranjan
1 Replies

5. Shell Programming and Scripting

fork and exec

I need to ssh to a remote server and run my script there. This is my script. $ssh = "ssh username@host"; $cmd = "$ssh 'cd <my dir> && < sudo Run_exe>'"; my $pid = fork; if ($pid == 0){ exec $cmd; } When I run this I get: pccons_getchar: got r == 0 (1 Reply)
Discussion started by: looza
1 Replies

6. Programming

How forbid use fork() in exec() program.

Hello World! I am writing code in C++ which have to launch another application X using exec(). I would like to set some limits on it using setrlimit etc... My problem is that i don't know how to forbid using fork() and strlimit by application X. How can i do it? (3 Replies)
Discussion started by: kzi
3 Replies

7. Programming

Fork and then exec problem with signals

Hi All, In my program i am handling SIGHUP signal. In the handler i fork and then exec on child process same binary file which is running. Parent process will die after 10 mins. Now my child process which was exec with same binary file is not receiving SIGHUP signal. Below is the progran code:... (6 Replies)
Discussion started by: sushil_shalin
6 Replies

8. Programming

Newbie question on exec,fork, wait,pipe C

Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine. So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies

9. UNIX for Dummies Questions & Answers

fork with exec

What is is difference between 'fork with exec' and 'fork without exec'? How both are related? (1 Reply)
Discussion started by: kkalyan
1 Replies

10. UNIX for Beginners Questions & Answers

Question about global environment variables & fork() exec()

Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies
YAZ_ITEMORDER(3)							 1							  YAZ_ITEMORDER(3)

yaz_itemorder - Prepares for Z39.50 Item Order with an ILL-Request package

SYNOPSIS
void yaz_itemorder (resource $id, array $args) DESCRIPTION
This function prepares for an Extended Services request using the Profile for the Use of Z39.50 Item Order Extended Service to Transport ILL (Profile/1). See this and the specification. PARAMETERS
o $id - The connection resource returned by yaz_connect(3). o $args - Must be an associative array with information about the Item Order request to be sent. The key of the hash is the name of the corresponding ASN.1 tag path. For example, the ISBN below the Item-ID has the key item-id,ISBN. The ILL-Request parameters are: transaction-id,initial-requester-id,person-or-institution-symbol,person transaction-id,initial-requester-id,person-or-institution- symbol,institution transaction-id,initial-requester-id,name-of-person-or-institution,name-of-person transaction-id,initial- requester-id,name-of-person-or-institution,name-of-institution transaction-id,transaction-group-qualifier transaction-id,transac- tion-qualifier transaction-id,sub-transaction-qualifier service-date-time,this,date service-date-time,this,time service-date- time,original,date service-date-time,original,time requester-id,person-or-institution-symbol,person requester-id,person-or-institu- tion-symbol,institution requester-id,name-of-person-or-institution,name-of-person requester-id,name-of-person-or-institution,name- of-institution responder-id,person-or-institution-symbol,person responder-id,person-or-institution-symbol,institution responder- id,name-of-person-or-institution,name-of-person responder-id,name-of-person-or-institution,name-of-institution transaction-type delivery-address,postal-address,name-of-person-or-institution,name-of-person delivery-address,postal-address,name-of-person-or- institution,name-of-institution delivery-address,postal-address,extended-postal-delivery-address delivery-address,postal- address,street-and-number delivery-address,postal-address,post-office-box delivery-address,postal-address,city delivery- address,postal-address,region delivery-address,postal-address,country delivery-address,postal-address,postal-code delivery- address,electronic-address,telecom-service-identifier delivery-address,electronic-address,telecom-service-addreess billing- address,postal-address,name-of-person-or-institution,name-of-person billing-address,postal-address,name-of-person-or-institu- tion,name-of-institution billing-address,postal-address,extended-postal-delivery-address billing-address,postal-address,street-and- number billing-address,postal-address,post-office-box billing-address,postal-address,city billing-address,postal-address,region billing-address,postal-address,country billing-address,postal-address,postal-code billing-address,electronic-address,telecom-ser- vice-identifier billing-address,electronic-address,telecom-service-addreess ill-service-type requester-optional-messages,can-send- RECEIVED requester-optional-messages,can-send-RETURNED requester-optional-messages,requester-SHIPPED requester-optional-mes- sages,requester-CHECKED-IN search-type,level-of-service search-type,need-before-date search-type,expiry-date search-type,expiry-flag place-on-hold client-id,client-name client-id,client-status client-id,client-identifier item-id,item-type item-id,call-number item- id,author item-id,title item-id,sub-title item-id,sponsoring-body item-id,place-of-publication item-id,publisher item-id,series- title-number item-id,volume-issue item-id,edition item-id,publication-date item-id,publication-date-of-component item-id,author-of- article item-id,title-of-article item-id,pagination item-id,ISBN item-id,ISSN item-id,additional-no-letters item-id,verification- reference-source copyright-complicance retry-flag forward-flag requester-note forward-note user-id contact-name contact-phone contact-email itemorder-item RETURN VALUES
No value is returned. PHP Documentation Group YAZ_ITEMORDER(3)
All times are GMT -4. The time now is 07:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy