However, when I have a program that forks and execs tel like:
pid = fork();
if (pid < 0) {
perror("fork failed");
exit(EXIT_FAILURE);
}
if (pid == 0) {
execlp("tel", "tel", user, what, (char *)0);
perror("execlp tel failed");
exit(EXIT_FAILURE);
}
and pass the string "la\nla\nla\n" to execlp()
The person sees
la
la
la
I'm pretty sure the exec() is clobbering tel. In the source code for tel, I see
void dotelegram(bool nl)
{
int ch;
/* Ask the user for a message if we don't already have one */
if (telmsg == NULL || telmsg[0] == '\0' || telmsg[0] == '\n')
{
if (nl) putchar('\n');
printf("Msg: ");
fgets(telmsg= linebuf, LBSIZE, stdin);
if (telmsg[0] == '\n') done(0);
}
/* slow down if we are sending stuff too fast */
if (f_wrthist != NULL)
{
sleep(check_flood());
register_tel();
}
/* send him a banner, if we weren't writing him already */
if (!nested_write())
sendbanner();
/* Send the telegram */
is_writing= TRUE;
while (*telmsg != '\0')
sendchar(*(telmsg++));
if (rec_only)
printf("SAVED\n");
else
printf("SENT\n");
}
I was thinking that tel might be confusing "string related" lines with "logical related" lines.
Possible ideas what might be going on or what to look for in the source code?
When I run
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
Below is a crude, but working example of what I mean. Please be gentle on the coding errors.
[cda@localhost ~]$ more input
la
[cda@localhost ~]$ ./flood cdalten
cda logged on more than once
Telegram to pts/5...Telegram from cda on pts/5 at 21:12 PDT ...
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
la
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)
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)
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)
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)
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)
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)
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)
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)
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)