-1

My process a.out is starting by a timeout command similar to:

timeout 1 ./a.out - < file.txt


It runs on a server and I have no control over that because it is part of a shell script that being invoked by the server automatically.

Is there any possibility or solution that I can implement so that a.out won't get killed until it finishes?

  • I already mapped signal 15 (SIGTERM) by SIG_IGN macro, so it runs about 5s instead of 1s.
  • If I send SIGKILL to timeout then both gets killed.
  • Sending SIGSTOP and SIGHUP to timeout seems to have no effect.

I searched a lot regarding this matter, but all questions and texts seems to be on timeout usage. Is there anything else I can do? like another signal, forking, preventing timeout to get time correctly, blocking signals, doing something in inline assembly, anything at all?

Thank you.

justsomeguy
  • 374
  • 1
  • 7
user174174
  • 479
  • 1
  • 6
  • 13
  • 2
    XY problem. Why use `timeout` if you don't want its functionality? What you're asking for is solved by not using `timeout`, but according to your question, this is not possible. – Panki Dec 16 '22 at 15:18
  • Please [edit] your question and add more details. Do you want to circumvent a time limit posed by some web site or testing environment? What program starts your program this way? What is the value of `PATH`? Can you provide an own program named `timeout`? – Bodo Dec 16 '22 at 15:33
  • @Panki I don't run that command, also clearly mentioned that I don't have control over that commad. process runs on a server in that form. why I should use timeout when I want to get rid of it? – user174174 Dec 16 '22 at 15:36
  • @Bodo yes, your guess is right. it runs on a server. Starts by a shell script that the arguments of timeout has passed to it, like, the shell script runs: timeout $1 ./a.out. PATH was encrypted but I did decode it, and timeout is at /usr/bin. unfortunately I don't have access to write there. – user174174 Dec 16 '22 at 15:46
  • **Please [edit] your question to add requested information**, don't use comments for this purpose. Apparently the server's administrators have set this timeout to limit the resource usage. Trying to circumvent this is not nice. If this is related to some coding contest or learning platform, the timeout might mean that your program contains errors like an endless loop for some input or that the complexity of your algorithm is too high. – Bodo Dec 16 '22 at 15:56
  • @Bodo updated the question. thanks. Im aware of that but whatever the purpose is doesn't make any difference on question – user174174 Dec 16 '22 at 16:17
  • @user174174 I'd argue it does make a difference in terms of the tools you'd use. Please don't assume bad intent from the people asking for clarification. – Marcus Müller Dec 16 '22 at 16:24
  • If the administrators of the server did their job right you cannot circumvent this timeout. As written in the first comment, this looks like an XY problem. With more information (as a separate question) about the purpose of your program and why you think it needs to run longer than the timeout we might check if there is a different solution to your basic problem. – Bodo Dec 16 '22 at 16:42
  • @Bodo and what if the administrators of the server didn’t do their job right? – user174174 Dec 16 '22 at 16:48
  • If they didn’t do their job right, then I'm wouldn't be sure there is no way to circumvent the timeout. But as you already tried to kill the `timeout` process without success, I assume that they know their job. If I were to program the server software, I would `fork` a process, call `setpgid` in the child to to make this a process group leader, `exec*` the `timeout` program with arguments, then `wait*` for the termination of any such process and kill the corresponding process group which would automatically kill your program and all its children. (or something similar) – Bodo Dec 16 '22 at 17:10

1 Answers1

0

If the administrators have not locked down the at queue you could try this

#!/bin/sh
# timeout 1 ./a.out - < file.txt
#
if [ "$1" != '_at_' ]
then
    # Queue task
    file="$(mktemp '/var/tmp/XXXXXXXXXX.at.tmp')"
    cat >"$file"
    ( echo "'$0' _at_ "$file" "$@" ) | at -b now
    sleep 60
    exit 0
fi

# Reattach stdin
exec 0<"$2"
rm -f "$2"
shift 2

# Run the real code here
# ...
roaima
  • 107,089
  • 14
  • 139
  • 261